forked from AdguardTeam/gomitmproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhopbyhop.go
37 lines (33 loc) · 894 Bytes
/
hopbyhop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gomitmproxy
import (
"net/http"
"strings"
)
// Hop-by-hop headers as defined by RFC2616.
//
// http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-7.1.3.1
var hopByHopHeaders = []string{
"Connection",
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Authorization",
"Proxy-Connection", // Non-standard, but required for HTTP/2.
"Te",
"Trailer",
"Transfer-Encoding",
"Upgrade",
}
// removeHopByHopHeaders removes hop-by-hop headers.
func removeHopByHopHeaders(header http.Header) {
// Additional hop-by-hop headers may be specified in `Connection` headers.
// http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-9.1
for _, vs := range header["Connection"] {
for _, v := range strings.Split(vs, ",") {
k := http.CanonicalHeaderKey(strings.TrimSpace(v))
header.Del(k)
}
}
for _, k := range hopByHopHeaders {
header.Del(k)
}
}