1
0
Fork 0

Forward Authentication: add X-Forwarded-Uri

This commit is contained in:
Sebastian Bauer 2017-12-10 00:58:21 +01:00 committed by Ludovic Fernandez
parent c446c291d9
commit 328be161d6
2 changed files with 42 additions and 2 deletions

View file

@ -12,6 +12,10 @@ import (
"github.com/vulcand/oxy/utils"
)
const (
xForwardedURI = "X-Forwarded-Uri"
)
// Forward the authentication to a external server
func Forward(config *types.Forward, w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
@ -122,4 +126,12 @@ func writeHeader(req *http.Request, forwardReq *http.Request, trustForwardHeader
} else {
forwardReq.Header.Del(forward.XForwardedHost)
}
if xfURI := req.Header.Get(xForwardedURI); xfURI != "" && trustForwardHeader {
forwardReq.Header.Set(xForwardedURI, xfURI)
} else if req.URL.RequestURI() != "" {
forwardReq.Header.Set(xForwardedURI, req.URL.RequestURI())
} else {
forwardReq.Header.Del(xForwardedURI)
}
}