-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhttp.go
More file actions
31 lines (29 loc) · 675 Bytes
/
http.go
File metadata and controls
31 lines (29 loc) · 675 Bytes
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
package main
import (
"io"
"net/http"
"strings"
)
func handleHTTP(w http.ResponseWriter, req *http.Request) {
resp, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
defer resp.Body.Close()
copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
_, _ = io.Copy(w, resp.Body)
}
func copyHeader(dst, src http.Header) {
for k, vs := range src {
switch strings.ToLower(k) {
case /*"connection",*/ "keepalive", "proxy-authenticate, proxy-authorization, te, trailer, transfer-encoding":
// skip
vs = []string{}
}
for _, v := range vs {
dst.Add(k, v)
}
}
}