aboutsummaryrefslogtreecommitdiff
path: root/http.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 /http.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 'http.go')
-rw-r--r--http.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/http.go b/http.go
index 384a7b3..9db9be5 100644
--- a/http.go
+++ b/http.go
@@ -1568,7 +1568,7 @@ func (resp *Response) WriteDeflateLevel(w *bufio.Writer, level int) error {
}
func (resp *Response) brotliBody(level int) error {
- if len(resp.Header.peek(strContentEncoding)) > 0 {
+ if len(resp.Header.ContentEncoding()) > 0 {
// It looks like the body is already compressed.
// Do not compress it again.
return nil
@@ -1618,12 +1618,12 @@ func (resp *Response) brotliBody(level int) error {
resp.body = w
resp.bodyRaw = nil
}
- resp.Header.SetCanonical(strContentEncoding, strBr)
+ resp.Header.SetContentEncodingBytes(strBr)
return nil
}
func (resp *Response) gzipBody(level int) error {
- if len(resp.Header.peek(strContentEncoding)) > 0 {
+ if len(resp.Header.ContentEncoding()) > 0 {
// It looks like the body is already compressed.
// Do not compress it again.
return nil
@@ -1673,12 +1673,12 @@ func (resp *Response) gzipBody(level int) error {
resp.body = w
resp.bodyRaw = nil
}
- resp.Header.SetCanonical(strContentEncoding, strGzip)
+ resp.Header.SetContentEncodingBytes(strGzip)
return nil
}
func (resp *Response) deflateBody(level int) error {
- if len(resp.Header.peek(strContentEncoding)) > 0 {
+ if len(resp.Header.ContentEncoding()) > 0 {
// It looks like the body is already compressed.
// Do not compress it again.
return nil
@@ -1728,7 +1728,7 @@ func (resp *Response) deflateBody(level int) error {
resp.body = w
resp.bodyRaw = nil
}
- resp.Header.SetCanonical(strContentEncoding, strDeflate)
+ resp.Header.SetContentEncodingBytes(strDeflate)
return nil
}