Support X-Forwarded-Port.

This commit is contained in:
Ludovic Fernandez 2017-08-21 17:54:02 +02:00 committed by Traefiker
parent 5313922bb7
commit 3f650bbd11
4 changed files with 11 additions and 4 deletions

6
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: b056b388f961ddc3509b19b4546d8dfc70fd50ebd1ca47f2fd2de67bf49ba01e
updated: 2017-08-12T14:15:06.346751095+02:00
hash: b970da88f72aebed9ac07a31db3f40045de0cd63190a2aae8ce18b55ec3f434a
updated: 2017-08-21T14:15:06.346751095+02:00
imports:
- name: cloud.google.com/go
version: 2e6a95edb1071d750f6d7db777bf66cd2997af6c
@ -477,7 +477,7 @@ imports:
- name: github.com/urfave/negroni
version: 490e6a555d47ca891a89a150d0c1ef3922dfffe9
- name: github.com/vulcand/oxy
version: d40fb60c9a1620892a6fc146dcdc891fb02bd488
version: 3772a8e4408fb033d00a947d340475e116854b1a
repo: https://github.com/containous/oxy.git
vcs: git
subpackages:

View file

@ -12,7 +12,7 @@ import:
- package: github.com/cenk/backoff
- package: github.com/containous/flaeg
- package: github.com/vulcand/oxy
version: d40fb60c9a1620892a6fc146dcdc891fb02bd488
version: 3772a8e4408fb033d00a947d340475e116854b1a
repo: https://github.com/containous/oxy.git
vcs: git
subpackages:

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"

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 != "" {