1
0
mirror of https://github.com/containous/traefik.git synced 2024-12-23 17:34:13 +03:00

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

6
glide.lock generated
View File

@ -1,5 +1,5 @@
hash: eddc889b1c0fc19ad91d886268e46ebdf85cd9e376e78b96b0d6661cc5842aca
updated: 2017-06-29T16:47:14.848940186+02:00
hash: 8b1dbedc74488a75ba15557befbf44cf56060bc562e7407ef9a09791ec5cabd6
updated: 2017-08-18T16:47:14.848940186+02:00
imports:
- name: cloud.google.com/go
version: 2e6a95edb1071d750f6d7db777bf66cd2997af6c
@ -411,7 +411,7 @@ imports:
- name: github.com/vdemeester/docker-events
version: be74d4929ec1ad118df54349fda4b0cba60f849b
- name: github.com/vulcand/oxy
version: 05a57556d820dc5c56721ebdefbafc15f36fac98
version: 321ed9ffd102941c736731b8e7bae811820d267d
repo: https://github.com/containous/oxy.git
vcs: git
subpackages:

View File

@ -8,7 +8,7 @@ import:
- package: github.com/cenk/backoff
- package: github.com/containous/flaeg
- package: github.com/vulcand/oxy
version: 05a57556d820dc5c56721ebdefbafc15f36fac98
version: 321ed9ffd102941c736731b8e7bae811820d267d
repo: https://github.com/containous/oxy.git
vcs: git
subpackages:

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

View File

@ -4,6 +4,7 @@ const (
XForwardedProto = "X-Forwarded-Proto"
XForwardedFor = "X-Forwarded-For"
XForwardedHost = "X-Forwarded-Host"
XForwardedPort = "X-Forwarded-Port"
XForwardedServer = "X-Forwarded-Server"
Connection = "Connection"
KeepAlive = "Keep-Alive"
@ -18,7 +19,6 @@ const (
SecWebsocketKey = "Sec-Websocket-Key"
SecWebsocketVersion = "Sec-Websocket-Version"
SecWebsocketExtensions = "Sec-Websocket-Extensions"
SecWebsocketProtocol = "Sec-Websocket-Protocol"
SecWebsocketAccept = "Sec-Websocket-Accept"
)
@ -42,7 +42,6 @@ var WebsocketDialHeaders = []string{
SecWebsocketKey,
SecWebsocketVersion,
SecWebsocketExtensions,
SecWebsocketProtocol,
SecWebsocketAccept,
}

View File

@ -32,6 +32,12 @@ func (rw *HeaderRewriter) Rewrite(req *http.Request) {
req.Header.Set(XForwardedProto, "http")
}
if xfp := req.Header.Get(XForwardedPort); xfp != "" && rw.TrustForwardHeader {
req.Header.Set(XForwardedPort, xfp)
} else if req.URL.Port() != "" {
req.Header.Set(XForwardedPort, req.URL.Port())
}
if xfh := req.Header.Get(XForwardedHost); xfh != "" && rw.TrustForwardHeader {
req.Header.Set(XForwardedHost, xfh)
} else if req.Host != "" {

View File

@ -38,7 +38,7 @@ func (s *StickySession) GetBackend(req *http.Request, servers []*url.URL) (*url.
}
func (s *StickySession) StickBackend(backend *url.URL, w *http.ResponseWriter) {
c := &http.Cookie{Name: s.cookiename, Value: backend.String()}
c := &http.Cookie{Name: s.cookiename, Value: backend.String(), Path: "/"}
http.SetCookie(*w, c)
return
}