]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/httputil: extract duplicate code as removeConnectionHeaders
authorKunpei Sakai <namusyaka@gmail.com>
Mon, 16 Oct 2017 05:40:10 +0000 (14:40 +0900)
committerTom Bergan <tombergan@google.com>
Mon, 16 Oct 2017 17:09:55 +0000 (17:09 +0000)
Change-Id: I50389752dcbf5d058ce11256a414be7955cdb77f
Reviewed-on: https://go-review.googlesource.com/71070
Run-TryBot: Tom Bergan <tombergan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tom Bergan <tombergan@google.com>
src/net/http/httputil/reverseproxy.go

index 0d514f529ba4e8e8dea78132efd65a4d6023653f..a0f36d1221d5271d511f4896249258d1f218cc31 100644 (file)
@@ -169,15 +169,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
        p.Director(outreq)
        outreq.Close = false
 
-       // 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, ",") {
-                       if f = strings.TrimSpace(f); f != "" {
-                               outreq.Header.Del(f)
-                       }
-               }
-       }
+       removeConnectionHeaders(outreq.Header)
 
        // Remove hop-by-hop headers to the backend. Especially
        // important is "Connection" because we want a persistent
@@ -205,15 +197,7 @@ 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)
-                       }
-               }
-       }
+       removeConnectionHeaders(res.Header)
 
        for _, h := range hopHeaders {
                res.Header.Del(h)
@@ -265,6 +249,18 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
        }
 }
 
+// removeConnectionHeaders removes hop-by-hop headers listed in the "Connection" header of h.
+// See RFC 2616, section 14.10.
+func removeConnectionHeaders(h http.Header) {
+       if c := h.Get("Connection"); c != "" {
+               for _, f := range strings.Split(c, ",") {
+                       if f = strings.TrimSpace(f); f != "" {
+                               h.Del(f)
+                       }
+               }
+       }
+}
+
 func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
        if p.FlushInterval != 0 {
                if wf, ok := dst.(writeFlusher); ok {