diff --git a/src/pkg/http/reverseproxy.go b/src/pkg/http/reverseproxy.go index 3a63db009f..3f8bfdc80c 100644 --- a/src/pkg/http/reverseproxy.go +++ b/src/pkg/http/reverseproxy.go @@ -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) diff --git a/src/pkg/http/reverseproxy_test.go b/src/pkg/http/reverseproxy_test.go index 663218d61b..8078c8d10d 100644 --- a/src/pkg/http/reverseproxy_test.go +++ b/src/pkg/http/reverseproxy_test.go @@ -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)