Skip to content

Commit

Permalink
refactor: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens committed Nov 23, 2017
1 parent f86ce27 commit 917ffb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions forward/fwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
dialer := websocket.DefaultDialer
if outReq.URL.Scheme == "wss" && f.tlsClientConfig != nil {
dialer.TLSClientConfig = f.tlsClientConfig.Clone()
//WebSocket is only in http/1.1
// WebSocket is only in http/1.1
dialer.TLSClientConfig.NextProtos = []string{"http/1.1"}
}
targetConn, resp, err := dialer.Dial(outReq.URL.String(), outReq.Header)
Expand Down Expand Up @@ -329,7 +329,7 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
return
}

//Only the targetConn choose to CheckOrigin or not
// Only the targetConn choose to CheckOrigin or not
upgrader := websocket.Upgrader{CheckOrigin: func(r *http.Request) bool {
return true
}}
Expand Down Expand Up @@ -357,26 +357,26 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
go replicate(targetConn.UnderlyingConn(), underlyingConn.UnderlyingConn(), "backend", "client")

// Try to read the first message
t, msg, err := targetConn.ReadMessage()
msgType, msg, err := targetConn.ReadMessage()
if err != nil {
log.Errorf("vulcand/oxy/forward/websocket: Couldn't read first message : %v", err)
} else {
underlyingConn.WriteMessage(t, msg)
underlyingConn.WriteMessage(msgType, msg)
}

go replicate(underlyingConn.UnderlyingConn(), targetConn.UnderlyingConn(), "client", "backend")
<-errc
}

// copyRequest makes a copy of the specified request.
// copyWebsocketRequest makes a copy of the specified request.
func (f *httpForwarder) copyWebSocketRequest(req *http.Request) (outReq *http.Request) {
outReq = new(http.Request)
*outReq = *req // includes shallow copies of maps, but we handle this below

outReq.URL = utils.CopyURL(req.URL)
outReq.URL.Scheme = req.URL.Scheme

//sometimes backends might be registered as HTTP/HTTPS servers so translate URLs to websocket URLs.
// sometimes backends might be registered as HTTP/HTTPS servers so translate URLs to websocket URLs.
switch req.URL.Scheme {
case "https":
outReq.URL.Scheme = "wss"
Expand All @@ -396,7 +396,7 @@ func (f *httpForwarder) copyWebSocketRequest(req *http.Request) (outReq *http.Re
outReq.URL.Host = req.URL.Host

outReq.Header = make(http.Header)
//gorilla websocket use this header to set the request.Host tested in checkSameOrigin
// gorilla websocket use this header to set the request.Host tested in checkSameOrigin
outReq.Header.Set("Host", outReq.Host)
utils.CopyHeaders(outReq.Header, req.Header)
utils.RemoveHeaders(outReq.Header, WebsocketDialHeaders...)
Expand Down
2 changes: 1 addition & 1 deletion forward/fwd_websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (s *FwdSuite) TestWebSocketUpgradeFailed(c *C) {

req.Write(conn)

//First request works with 400
// First request works with 400
br := bufio.NewReader(conn)
resp, err := http.ReadResponse(br, req)

Expand Down

0 comments on commit 917ffb7

Please sign in to comment.