Commit 0b513699 authored by Matt Holt's avatar Matt Holt

Merge pull request #356 from Luit/master

proxy: Two small websocket fixes
parents 4dbb4274 1fb66d53
...@@ -155,9 +155,9 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr ...@@ -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
...@@ -169,7 +169,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr ...@@ -169,7 +169,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr
} }
defer conn.Close() defer conn.Close()
backendConn, err := net.Dial("tcp", outreq.Host) backendConn, err := net.Dial("tcp", outreq.URL.Host)
if err != nil { if err != nil {
return err return err
} }
...@@ -182,6 +182,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request, extr ...@@ -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)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment