aboutsummaryrefslogtreecommitdiff
path: root/header.go
diff options
context:
space:
mode:
authorGravatar AutumnSun <qsy1314@mail.ustc.edu.cn> 2023-07-02 18:40:26 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-02 12:40:26 +0200
commit0d0bbfee5a8dd12a82e442d3cbb11e56726dd06e (patch)
tree9cf86b8ad5e5709c3907eda99d5919acafc242e1 /header.go
parentRemove unnecessary indent blocks (#1586) (diff)
downloadfasthttp-0d0bbfee5a8dd12a82e442d3cbb11e56726dd06e.tar.gz
fasthttp-0d0bbfee5a8dd12a82e442d3cbb11e56726dd06e.tar.bz2
fasthttp-0d0bbfee5a8dd12a82e442d3cbb11e56726dd06e.zip
Auto add 'Vary' header after compression (#1585)
* Auto add 'Vary' header after compression Add config `SetAddVaryHeaderForCompression` to enable 'Vary: Accept-Encoding' header when compression is used. * feat: always set the Vary header * create and use `ResponseHeader.AddVaryBytes` * not export 'AddVaryBytes'
Diffstat (limited to 'header.go')
-rw-r--r--header.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/header.go b/header.go
index 5665e79..ca9062f 100644
--- a/header.go
+++ b/header.go
@@ -344,6 +344,18 @@ func (h *ResponseHeader) SetContentEncodingBytes(contentEncoding []byte) {
h.contentEncoding = append(h.contentEncoding[:0], contentEncoding...)
}
+// addVaryBytes add value to the 'Vary' header if it's not included
+func (h *ResponseHeader) addVaryBytes(value []byte) {
+ v := h.peek(strVary)
+ if len(v) == 0 {
+ // 'Vary' is not set
+ h.SetBytesV(HeaderVary, value)
+ } else if !bytes.Contains(v, value) {
+ // 'Vary' is set and not contains target value
+ h.SetBytesV(HeaderVary, append(append(v, ','), value...))
+ } // else: 'Vary' is set and contains target value
+}
+
// Server returns Server header value.
func (h *ResponseHeader) Server() []byte {
return h.server