Websocket parameters and protocol.

This commit is contained in:
Ludovic Fernandez 2017-08-20 19:02:02 +02:00 committed by Traefiker
parent 413ed62933
commit 40e18db838
6 changed files with 17 additions and 11 deletions

View file

@ -258,7 +258,6 @@ func (f *websocketForwarder) serveHTTP(w http.ResponseWriter, req *http.Request,
if outReq.URL.Scheme == "wss" && f.TLSClientConfig != nil {
dialer.TLSClientConfig = f.TLSClientConfig
}
targetConn, resp, err := dialer.Dial(outReq.URL.String(), outReq.Header)
if err != nil {
ctx.log.Errorf("Error dialing `%v`: %v", outReq.Host, err)
@ -308,7 +307,6 @@ func (f *websocketForwarder) copyRequest(req *http.Request, u *url.URL) (outReq
outReq.URL = utils.CopyURL(req.URL)
outReq.URL.Scheme = u.Scheme
outReq.URL.Path = outReq.RequestURI
//sometimes backends might be registered as HTTP/HTTPS servers so translate URLs to websocket URLs.
switch u.Scheme {
@ -318,9 +316,12 @@ func (f *websocketForwarder) copyRequest(req *http.Request, u *url.URL) (outReq
outReq.URL.Scheme = "ws"
}
if requestURI, err := url.ParseRequestURI(outReq.RequestURI); err == nil {
outReq.URL.Path = requestURI.Path
outReq.URL.RawQuery = requestURI.RawQuery
}
outReq.URL.Host = u.Host
// raw query is already included in RequestURI, so ignore it to avoid dupes
outReq.URL.RawQuery = ""
outReq.Header = make(http.Header)
//gorilla websocket use this header to set the request.Host tested in checkSameOrigin