Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content encoding not parsing comma separated lists of encodings #960

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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,
},
}

for _, tt := range tests {
Expand Down