-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttp.go
81 lines (72 loc) · 1.52 KB
/
http.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
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
77
78
79
80
81
// Froxy - HTTP over SSH proxy
//
// Copyright (C) 2019 and up by Alexander Pevzner ([email protected])
// See LICENSE for license terms and conditions
//
// HTTP utilities
package main
import (
"net/http"
"net/textproto"
"strings"
)
//
// List of HTTP hop-by-hop headers
//
var httpHopByHopHeaders = []string{
"Connection",
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Connection",
"Proxy-Authorization",
"Te",
"Trailer",
"Transfer-Encoding",
}
//
// Copy HTTP headers
//
func httpCopyHeaders(dst, src http.Header) {
for k, v := range src {
dst[k] = v
}
}
//
// Remove hop-by-hop headers.
//
// Upgrade headers are preserved, and if present, this function
// returns true
//
func httpRemoveHopByHopHeaders(hdr http.Header) bool {
// We must delete headers listed in Connection
if c, ok := hdr["Connection"]; ok {
for _, v := range c {
for _, k := range strings.Split(v, ",") {
if k = strings.TrimSpace(k); k != "" {
k = textproto.CanonicalMIMEHeaderKey(k)
if k != "Upgrade" {
delete(hdr, k)
}
}
}
}
}
// And also standard Hop-by-hop headers
for _, k := range httpHopByHopHeaders {
delete(hdr, k)
}
// Restore "Connection: Upgrade" header
_, upgraded := hdr["Upgrade"]
if upgraded {
hdr["Connection"] = []string{"Upgrade"}
}
return upgraded
}
//
// Set response headers to disable cacheing
//
func httpNoCache(w http.ResponseWriter) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
}