1
0
mirror of https://github.com/golang/go synced 2024-11-24 23:07:56 -07:00

undo CL 5302057 / dac58d9c9e4a

need a clean base from weekly.2011-10-25 for rune change

««« original CL description
http: remove Connection header in ReverseProxy

Fixes #2342

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5302057
»»»

R=rsc
CC=golang-dev
https://golang.org/cl/5294068
This commit is contained in:
Andrew Gerrand 2011-10-26 14:16:34 +09:00
parent 7c5d90dfbd
commit 5abb29d1b8
2 changed files with 6 additions and 24 deletions

View File

@ -69,14 +69,6 @@ func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
return &ReverseProxy{Director: director}
}
func copyHeader(dst, src Header) {
for k, vv := range src {
for _, v := range vv {
dst.Add(k, v)
}
}
}
func (p *ReverseProxy) ServeHTTP(rw ResponseWriter, req *Request) {
transport := p.Transport
if transport == nil {
@ -92,16 +84,6 @@ func (p *ReverseProxy) ServeHTTP(rw ResponseWriter, req *Request) {
outreq.ProtoMinor = 1
outreq.Close = false
// Remove the connection header to the backend. We want a
// persistent connection, regardless of what the client sent
// to us. This is modifying the same underlying map from req
// (shallow copied above) so we only copy it if necessary.
if outreq.Header.Get("Connection") != "" {
outreq.Header = make(Header)
copyHeader(outreq.Header, req.Header)
outreq.Header.Del("Connection")
}
if clientIp, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
outreq.Header.Set("X-Forwarded-For", clientIp)
}
@ -113,7 +95,12 @@ func (p *ReverseProxy) ServeHTTP(rw ResponseWriter, req *Request) {
return
}
copyHeader(rw.Header(), res.Header)
hdr := rw.Header()
for k, vv := range res.Header {
for _, v := range vv {
hdr.Add(k, v)
}
}
rw.WriteHeader(res.StatusCode)

View File

@ -24,9 +24,6 @@ func TestReverseProxy(t *testing.T) {
if r.Header.Get("X-Forwarded-For") == "" {
t.Errorf("didn't get X-Forwarded-For header")
}
if c := r.Header.Get("Connection"); c != "" {
t.Errorf("handler got Connection header value %q", c)
}
if g, e := r.Host, "some-name"; g != e {
t.Errorf("backend got Host header %q, want %q", g, e)
}
@ -46,8 +43,6 @@ func TestReverseProxy(t *testing.T) {
getReq, _ := NewRequest("GET", frontend.URL, nil)
getReq.Host = "some-name"
getReq.Header.Set("Connection", "close")
getReq.Close = true
res, err := DefaultClient.Do(getReq)
if err != nil {
t.Fatalf("Get: %v", err)