fix: fix host forwrading
This commit is contained in:
@@ -70,12 +70,12 @@ func (proxyRoute ProxyRoute) ProxyHandler() http.HandlerFunc {
|
||||
}
|
||||
return
|
||||
}
|
||||
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
|
||||
r.Header.Set("X-Forwarded-For", getRealIP(r))
|
||||
r.Header.Set("X-Real-IP", getRealIP(r))
|
||||
// Update the headers to allow for SSL redirection
|
||||
if !proxyRoute.disableXForward {
|
||||
if !proxyRoute.disableHostFording {
|
||||
r.URL.Scheme = targetURL.Scheme
|
||||
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
|
||||
r.Header.Set("X-Forwarded-For", getRealIP(r))
|
||||
r.Header.Set("X-Real-IP", getRealIP(r))
|
||||
r.Host = targetURL.Host
|
||||
}
|
||||
backendURL, _ := url.Parse(proxyRoute.destination)
|
||||
|
||||
@@ -99,13 +99,13 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
||||
} else {
|
||||
for _, midPath := range rMiddleware.Paths {
|
||||
proxyRoute := ProxyRoute{
|
||||
path: route.Path,
|
||||
rewrite: route.Rewrite,
|
||||
destination: route.Destination,
|
||||
backends: route.Backends,
|
||||
disableXForward: route.DisableHeaderXForward,
|
||||
methods: route.Methods,
|
||||
cors: route.Cors,
|
||||
path: route.Path,
|
||||
rewrite: route.Rewrite,
|
||||
destination: route.Destination,
|
||||
backends: route.Backends,
|
||||
disableHostFording: route.DisableHostFording,
|
||||
methods: route.Methods,
|
||||
cors: route.Cors,
|
||||
}
|
||||
secureRouter := r.PathPrefix(util.ParseRoutePath(route.Path, midPath)).Subrouter()
|
||||
//callBackRouter := r.PathPrefix(util.ParseRoutePath(route.Path, "/callback")).Subrouter()
|
||||
@@ -206,13 +206,13 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
||||
}
|
||||
}
|
||||
proxyRoute := ProxyRoute{
|
||||
path: route.Path,
|
||||
rewrite: route.Rewrite,
|
||||
destination: route.Destination,
|
||||
backends: route.Backends,
|
||||
methods: route.Methods,
|
||||
disableXForward: route.DisableHeaderXForward,
|
||||
cors: route.Cors,
|
||||
path: route.Path,
|
||||
rewrite: route.Rewrite,
|
||||
destination: route.Destination,
|
||||
backends: route.Backends,
|
||||
methods: route.Methods,
|
||||
disableHostFording: route.DisableHostFording,
|
||||
cors: route.Cors,
|
||||
}
|
||||
// create route
|
||||
router := r.PathPrefix(route.Path).Subrouter()
|
||||
|
||||
@@ -155,12 +155,12 @@ type Route struct {
|
||||
// Cors contains the route cors headers
|
||||
Cors Cors `yaml:"cors"`
|
||||
RateLimit int `yaml:"rateLimit"`
|
||||
// DisableHeaderXForward Disable X-forwarded header.
|
||||
// DisableHostFording Disable X-forwarded header.
|
||||
//
|
||||
// [X-Forwarded-Host, X-Forwarded-For, Host, Scheme ]
|
||||
//
|
||||
// It will not match the backend route
|
||||
DisableHeaderXForward bool `yaml:"disableHeaderXForward"`
|
||||
DisableHostFording bool `yaml:"disableHostFording"`
|
||||
// InterceptErrors intercepts backend errors based on the status codes
|
||||
//
|
||||
// Eg: [ 403, 405, 500 ]
|
||||
@@ -234,14 +234,14 @@ type GatewayServer struct {
|
||||
middlewares []Middleware
|
||||
}
|
||||
type ProxyRoute struct {
|
||||
path string
|
||||
rewrite string
|
||||
destination string
|
||||
backends []string
|
||||
healthCheck RouteHealthCheck
|
||||
methods []string
|
||||
cors Cors
|
||||
disableXForward bool
|
||||
path string
|
||||
rewrite string
|
||||
destination string
|
||||
backends []string
|
||||
healthCheck RouteHealthCheck
|
||||
methods []string
|
||||
cors Cors
|
||||
disableHostFording bool
|
||||
}
|
||||
type RoutePath struct {
|
||||
route Route
|
||||
|
||||
Reference in New Issue
Block a user