diff options
author | Sina Siadat <siadat@gmail.com> | 2016-08-27 20:46:25 +0430 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-02 16:21:38 +0000 |
commit | 03cff2e115277951108d3e00298ae1cb0b0b7fb6 (patch) | |
tree | 71ba8c1b0ab34637ee0eb0f0c37006a52f63d50c /src/net/http/httputil/reverseproxy.go | |
parent | 82bc0d4e80870f25805029ef0e1e844ace7bf068 (diff) | |
download | go-03cff2e115277951108d3e00298ae1cb0b0b7fb6.tar.gz go-03cff2e115277951108d3e00298ae1cb0b0b7fb6.zip |
net/http/httputil: remove proxied headers mentioned in connection-tokens
RFC 2616, section 14.10 says:
>>>
HTTP/1.1 proxies MUST parse the Connection header field before a message
is forwarded and, for each connection-token in this field, remove any
header field(s) from the message with the same name as the
connection-token. Connection options are signaled by the presence of a
connection-token in the Connection header field, not by any
corresponding additional header field(s), since the additional header
field may not be sent if there are no parameters associated with that
connection option.
<<<
The same requirement was included in RFC 7230, section 6.1.
Fixes #16875
Change-Id: I57ad4a4a17775537c8810d0edd7de1604317b5fa
Reviewed-on: https://go-review.googlesource.com/27970
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 | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index 49c120afde..79831b3a97 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -184,6 +184,16 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { outreq.ProtoMinor = 1 outreq.Close = false + // Remove headers with the same name as the connection-tokens. + // See RFC 2616, section 14.10. + if c := outreq.Header.Get("Connection"); c != "" { + for _, f := range strings.Split(c, ",") { + if f = strings.TrimSpace(f); f != "" { + outreq.Header.Del(f) + } + } + } + // Remove hop-by-hop headers to the backend. Especially // important is "Connection" because we want a persistent // connection, regardless of what the client sent to us. This |