Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions middleware/content_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ func AllowContentEncoding(contentEncoding ...string) func(next http.Handler) htt
return
}
// All encodings in the request must be allowed
for _, encoding := range requestEncodings {
if _, ok := allowedEncodings[strings.TrimSpace(strings.ToLower(encoding))]; !ok {
w.WriteHeader(http.StatusUnsupportedMediaType)
return
for _, encodingList := range requestEncodings {
encodings := strings.Split(encodingList, ",")
for _, encoding := range encodings {
if _, ok := allowedEncodings[strings.TrimSpace(strings.ToLower(encoding))]; !ok {
w.WriteHeader(http.StatusUnsupportedMediaType)
return
}
}
}
next.ServeHTTP(w, r)
Expand Down
10 changes: 10 additions & 0 deletions middleware/content_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ func TestContentEncodingMiddleware(t *testing.T) {
encodings: []string{"deflate", "gzip"},
expectedStatus: 200,
},
{
name: "Support for deflate and gzip encoding",
encodings: []string{"deflate, gzip"},
expectedStatus: 200,
},
{
name: "No support for deflate and br encoding",
encodings: []string{"deflate", "br"},
expectedStatus: 415,
},
{
name: "No support for deflate and br encoding",
encodings: []string{"deflate, br"},
expectedStatus: 415,
},
Comment on lines +52 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests with some qvalue ;q= per https://www.rfc-editor.org/rfc/rfc2616#page-102?

       Accept-Encoding: compress, gzip
       Accept-Encoding:
       Accept-Encoding: *
       Accept-Encoding: compress;q=0.5, gzip;q=1.0
       Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0

}

for _, tt := range tests {
Expand Down