diff --git a/middleware/proxy/reverseproxy.go b/middleware/proxy/reverseproxy.go index f9da992e..90e54667 100644 --- a/middleware/proxy/reverseproxy.go +++ b/middleware/proxy/reverseproxy.go @@ -155,9 +155,9 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr if err != nil { return err } - defer res.Body.Close() if res.StatusCode == http.StatusSwitchingProtocols && res.Header.Get("Upgrade") == "websocket" { + res.Body.Close() hj, ok := rw.(http.Hijacker) if !ok { return nil @@ -182,6 +182,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr }() io.Copy(conn, backendConn) // read tcp stream from backend. } else { + defer res.Body.Close() for _, h := range hopHeaders { res.Header.Del(h) }