Skip to content

Commit

Permalink
Fixes in handling websockets (#77)
Browse files Browse the repository at this point in the history
* Fix websockets forwarding

Copying request and closing connections fixes

Signed-off-by: Mariusz Borsa [email protected]

* Don't hardcode Proto/Minor/Major in downstream websocket request

* Updated websocket proxying logs to be clearer
  • Loading branch information
wrotki authored and archis-polyverse committed Jun 16, 2017
1 parent 993b3d2 commit 77cbabd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ _testmain.go
*.exe
*.test
*.prof
.idea/

flymake_*
14 changes: 11 additions & 3 deletions forward/fwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
}
go replicate(targetConn, underlyingConn, "backend", "client")
go replicate(underlyingConn, targetConn, "client", "backend")
err = <-errc
log.Infof("vulcand/oxy/forward/websocket: websocket proxying complete: %v", err)
err = <-errc // One goroutine complete
log.Infof("vulcand/oxy/forward/websocket: first proxying connection closed: %v", err)
err = <-errc // Both goroutines complete
log.Infof("vulcand/oxy/forward/websocket: second proxying connection closed: %v", err)
}

// copyRequest makes a copy of the specified request.
Expand All @@ -349,13 +351,19 @@ func (f *httpForwarder) copyWebSocketRequest(req *http.Request) (outReq *http.Re
}

outReq.URL.Host = req.URL.Host
outReq.URL.Path = req.RequestURI
outReq.URL.Opaque = req.RequestURI

// Do not pass client Host header unless optsetter PassHostHeader is set.
if !f.passHost {
outReq.Host = req.Host
}

// Overwrite close flag so we can keep persistent connection for the backend servers
outReq.Close = false

outReq.Header = make(http.Header)
utils.CopyHeaders(outReq.Header, req.Header)

if f.rewriter != nil {
f.rewriter.Rewrite(outReq)
}
Expand Down

0 comments on commit 77cbabd

Please sign in to comment.