diff options
author | Sina Siadat <siadat@gmail.com> | 2016-09-08 11:39:12 +0430 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-08 19:12:03 +0000 |
commit | daa7c607d269e4779b74174032639b552174868f (patch) | |
tree | 0f15c9639cfc111d9dcf1da154d546ae4a2390e6 /src/net/http/httputil/reverseproxy.go | |
parent | ed8f207940c8787d344664a43071b235e2ce5c68 (diff) | |
download | go-daa7c607d269e4779b74174032639b552174868f.tar.gz go-daa7c607d269e4779b74174032639b552174868f.zip |
net/http/httputil: remove custom hop-by-hop headers from response in ReverseProxy
Hop-by-hop headers (explicitly mentioned in RFC 2616) were already
removed from the response. This removes the custom hop-by-hop
headers listed in the "Connection" header of the response.
Updates #16875
Change-Id: I6b8f261d38b8d72040722f3ded29755ef0303427
Reviewed-on: https://go-review.googlesource.com/28810
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r-- | src/net/http/httputil/reverseproxy.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index 2b38e0fdd8..f8b60b6d33 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -156,7 +156,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { // copied above) so we only copy it if necessary. copiedHeaders := false - // Remove headers with the same name as the connection-tokens. + // Remove hop-by-hop headers listed in the "Connection" header. // See RFC 2616, section 14.10. if c := outreq.Header.Get("Connection"); c != "" { for _, f := range strings.Split(c, ",") { @@ -202,6 +202,16 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { return } + // Remove hop-by-hop headers listed in the + // "Connection" header of the response. + if c := res.Header.Get("Connection"); c != "" { + for _, f := range strings.Split(c, ",") { + if f = strings.TrimSpace(f); f != "" { + res.Header.Del(f) + } + } + } + for _, h := range hopHeaders { res.Header.Del(h) } |