Strip unsupported directives from Accept-Encoding

This commit is contained in:
David Stotijn
2022-03-21 14:56:05 +01:00
parent 71acd6e9ef
commit 38bd04b80b

View File

@ -11,6 +11,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"strings"
"time" "time"
"github.com/oklog/ulid" "github.com/oklog/ulid"
@ -120,6 +121,25 @@ func (p *Proxy) modifyRequest(r *http.Request) {
// set this header. // set this header.
r.Header["X-Forwarded-For"] = nil r.Header["X-Forwarded-For"] = nil
// Strip unsupported encodings.
if acceptEncs := r.Header.Get("Accept-Encoding"); acceptEncs != "" {
directives := strings.Split(acceptEncs, ",")
updated := make([]string, 0, len(directives))
for _, directive := range directives {
stripped := strings.TrimSpace(directive)
if strings.HasPrefix(stripped, "*") || strings.HasPrefix(stripped, "gzip") {
updated = append(updated, stripped)
}
}
if len(updated) == 0 {
r.Header.Del("Accept-Encoding")
} else {
r.Header.Set("Accept-Encoding", strings.Join(updated, ", "))
}
}
fn := nopReqModifier fn := nopReqModifier
for i := len(p.reqModifiers) - 1; i >= 0; i-- { for i := len(p.reqModifiers) - 1; i >= 0; i-- {