aboutsummaryrefslogtreecommitdiff
path: root/fs_test.go
diff options
context:
space:
mode:
authorGravatar Sergey Ponomarev <stokito@gmail.com> 2022-06-05 16:47:59 +0300
committerGravatar GitHub <noreply@github.com> 2022-06-05 15:47:59 +0200
commitc9f43eaa1b02d6867e489a39e92926c68facb60c (patch)
tree2f5343a5572a07eb207d2e7caf7b2480aad18c37 /fs_test.go
parentOptimize server connection close logic (#1310) (diff)
downloadfasthttp-c9f43eaa1b02d6867e489a39e92926c68facb60c.tar.gz
fasthttp-c9f43eaa1b02d6867e489a39e92926c68facb60c.tar.bz2
fasthttp-c9f43eaa1b02d6867e489a39e92926c68facb60c.zip
Response.ContentEncoding(): store as field and avoid using Header.SetCanonical() (#1311)
* Response.ContentEncoding(): store as field The CE is not so often used for plain APIs responses and even not so often used for static files and on the fly compression. But still it should be checked each time. Also having a dedicated field getter and setter simplifies code * header.go Use shorter Response.setNonSpecial() and Request.setNonSpecial() methods instead of SetCanonical() The change should improve performance because the setSpecialHeader() call is omitted. As a downside on adding a new basic header field all putHeader() must be replaced with a direct getter and setter.
Diffstat (limited to 'fs_test.go')
-rw-r--r--fs_test.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/fs_test.go b/fs_test.go
index de9f8c1..693d1a4 100644
--- a/fs_test.go
+++ b/fs_test.go
@@ -133,7 +133,7 @@ func TestServeFileHead(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
- ce := resp.Header.Peek(HeaderContentEncoding)
+ ce := resp.Header.ContentEncoding()
if len(ce) > 0 {
t.Fatalf("Unexpected 'Content-Encoding' %q", ce)
}
@@ -225,7 +225,7 @@ func TestServeFileCompressed(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
- ce := resp.Header.Peek(HeaderContentEncoding)
+ ce := resp.Header.ContentEncoding()
if string(ce) != "gzip" {
t.Fatalf("Unexpected 'Content-Encoding' %q. Expecting %q", ce, "gzip")
}
@@ -254,7 +254,7 @@ func TestServeFileCompressed(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
- ce = resp.Header.Peek(HeaderContentEncoding)
+ ce = resp.Header.ContentEncoding()
if string(ce) != "br" {
t.Fatalf("Unexpected 'Content-Encoding' %q. Expecting %q", ce, "br")
}
@@ -290,7 +290,7 @@ func TestServeFileUncompressed(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
- ce := resp.Header.Peek(HeaderContentEncoding)
+ ce := resp.Header.ContentEncoding()
if len(ce) > 0 {
t.Fatalf("Unexpected 'Content-Encoding' %q", ce)
}
@@ -567,7 +567,7 @@ func testFSCompress(t *testing.T, h RequestHandler, filePath string) {
if resp.StatusCode() != StatusOK {
t.Errorf("unexpected status code: %d. Expecting %d. filePath=%q", resp.StatusCode(), StatusOK, filePath)
}
- ce := resp.Header.Peek(HeaderContentEncoding)
+ ce := resp.Header.ContentEncoding()
if string(ce) != "" {
t.Errorf("unexpected content-encoding %q. Expecting empty string. filePath=%q", ce, filePath)
}
@@ -586,7 +586,7 @@ func testFSCompress(t *testing.T, h RequestHandler, filePath string) {
if resp.StatusCode() != StatusOK {
t.Errorf("unexpected status code: %d. Expecting %d. filePath=%q", resp.StatusCode(), StatusOK, filePath)
}
- ce = resp.Header.Peek(HeaderContentEncoding)
+ ce = resp.Header.ContentEncoding()
if string(ce) != "gzip" {
t.Errorf("unexpected content-encoding %q. Expecting %q. filePath=%q", ce, "gzip", filePath)
}
@@ -611,7 +611,7 @@ func testFSCompress(t *testing.T, h RequestHandler, filePath string) {
if resp.StatusCode() != StatusOK {
t.Errorf("unexpected status code: %d. Expecting %d. filePath=%q", resp.StatusCode(), StatusOK, filePath)
}
- ce = resp.Header.Peek(HeaderContentEncoding)
+ ce = resp.Header.ContentEncoding()
if string(ce) != "br" {
t.Errorf("unexpected content-encoding %q. Expecting %q. filePath=%q", ce, "br", filePath)
}