mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Strip unsupported directives from Accept-Encoding
This commit is contained in:
@ -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-- {
|
||||||
|
Reference in New Issue
Block a user