-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathheader.go
More file actions
76 lines (67 loc) · 2.45 KB
/
header.go
File metadata and controls
76 lines (67 loc) · 2.45 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package mitmproxy
import (
"net/http"
"net/textproto"
"golang.org/x/net/http/httpguts"
)
const (
HttpHeaderContentType = "Content-Type"
HttpHeaderConnection = "Connection"
HttpHeaderKeepAlive = "Keep-Alive"
HttpHeaderProxyAuthenticate = "Proxy-Authenticate"
HttpHeaderProxyAuthorization = "Proxy-Authorization"
HttpHeaderProxyConnection = "Proxy-Connection"
HttpHeaderProxyAgent = "Proxy-Agent"
HttpHeaderTe = "Te"
HttpHeaderTrailers = "Trailers"
HttpHeaderTransferEncoding = "Transfer-Encoding"
HttpHeaderUpgrade = "Upgrade"
HttpHeaderSecWebsocketKey = "Sec-Websocket-Key"
HttpHeaderSecWebsocketVersion = "Sec-Websocket-Version"
HttpHeaderSecWebsocketExtensions = "Sec-Websocket-Extensions"
HttpHeaderAcceptEncoding = "Accept-Encoding"
HttpHeaderContentEncoding = "Content-Encoding"
HttpHeaderContentLength = "Content-Length"
HttpHeaderHttp2Settings = "HTTP2-Settings"
)
var (
HttpResponseConnectionEstablished = []byte("HTTP/1.1 200 Connection Established\r\n\r\n")
H2CUpgradeResponseSwitchingProtocols = []byte("HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: h2c\r\n\r\n")
)
var (
// Hop-by-hop headers. These are removed when sent to the backend.
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
hopByHopHeaders = []string{
HttpHeaderConnection,
HttpHeaderKeepAlive,
HttpHeaderProxyAuthenticate,
HttpHeaderProxyAuthorization,
HttpHeaderTe,
HttpHeaderTrailers,
HttpHeaderTransferEncoding,
HttpHeaderUpgrade,
HttpHeaderProxyConnection,
}
)
func removeProxyHeaders(header http.Header) {
header.Del(HttpHeaderProxyAuthenticate)
header.Del(HttpHeaderProxyAuthorization)
header.Del(HttpHeaderProxyConnection)
header.Del(HttpHeaderProxyAgent)
}
func removeHopByHopRequestHeaders(header http.Header) {
for _, h := range hopByHopHeaders {
header.Del(h)
}
}
func removeWebsocketRequestHeaders(header http.Header) {
header.Del(HttpHeaderUpgrade)
header.Del(HttpHeaderConnection)
header.Del(HttpHeaderSecWebsocketKey)
header.Del(HttpHeaderSecWebsocketVersion)
header.Del(HttpHeaderSecWebsocketExtensions)
}
func isWSUpgrade(h http.Header) bool {
return httpguts.HeaderValuesContainsToken(h[textproto.CanonicalMIMEHeaderKey("Upgrade")], "websocket") &&
httpguts.HeaderValuesContainsToken(h[textproto.CanonicalMIMEHeaderKey("Connection")], "Upgrade")
}