Close proxy's backend request earlier when re-connecting for websocket

This commit is contained in:
Luit van Drongelen 2015-11-21 20:03:46 +01:00
parent f0b1edaf8c
commit 1fb66d534a

View File

@ -155,9 +155,9 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close()
if res.StatusCode == http.StatusSwitchingProtocols && res.Header.Get("Upgrade") == "websocket" { if res.StatusCode == http.StatusSwitchingProtocols && res.Header.Get("Upgrade") == "websocket" {
res.Body.Close()
hj, ok := rw.(http.Hijacker) hj, ok := rw.(http.Hijacker)
if !ok { if !ok {
return nil 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. io.Copy(conn, backendConn) // read tcp stream from backend.
} else { } else {
defer res.Body.Close()
for _, h := range hopHeaders { for _, h := range hopHeaders {
res.Header.Del(h) res.Header.Del(h)
} }