diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2022-06-05 16:47:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-05 15:47:59 +0200 |
commit | c9f43eaa1b02d6867e489a39e92926c68facb60c (patch) | |
tree | 2f5343a5572a07eb207d2e7caf7b2480aad18c37 /http_test.go | |
parent | Optimize server connection close logic (#1310) (diff) | |
download | fasthttp-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 'http_test.go')
-rw-r--r-- | http_test.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/http_test.go b/http_test.go index 71d5c6e..8d99cdd 100644 --- a/http_test.go +++ b/http_test.go @@ -1383,7 +1383,7 @@ func testResponseDeflateExt(t *testing.T, r *Response, s string) { t.Fatalf("unexpected error: %v", err) } - ce := r1.Header.Peek(HeaderContentEncoding) + ce := r1.Header.ContentEncoding() var body []byte if isCompressible { if string(ce) != "deflate" { @@ -1436,7 +1436,7 @@ func testResponseGzipExt(t *testing.T, r *Response, s string) { t.Fatalf("unexpected error: %v", err) } - ce := r1.Header.Peek(HeaderContentEncoding) + ce := r1.Header.ContentEncoding() var body []byte if isCompressible { if string(ce) != "gzip" { @@ -1992,7 +1992,7 @@ func testResponseReadWithoutBody(t *testing.T, resp *Response, s string, skipBod if len(resp.Body()) != 0 { t.Fatalf("Unexpected response body %q. Expected %q. response=%q", resp.Body(), "", s) } - verifyResponseHeader(t, &resp.Header, expectedStatusCode, expectedContentLength, expectedContentType) + verifyResponseHeader(t, &resp.Header, expectedStatusCode, expectedContentLength, expectedContentType, "") verifyResponseTrailer(t, &resp.Header, expectedTrailer) // verify that ordinal response is read after null-body response @@ -2269,7 +2269,7 @@ func testResponseReadSuccess(t *testing.T, resp *Response, response string, expe t.Fatalf("Unexpected error: %v", err) } - verifyResponseHeader(t, &resp.Header, expectedStatusCode, expectedContentLength, expectedContentType) + verifyResponseHeader(t, &resp.Header, expectedStatusCode, expectedContentLength, expectedContentType, "") if !bytes.Equal(resp.Body(), []byte(expectedBody)) { t.Fatalf("Unexpected body %q. Expected %q", resp.Body(), []byte(expectedBody)) } |