Skip to content

Commit

Permalink
Removing host header for all requests to event-service
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanh committed Mar 4, 2020
1 parent 3acc8a0 commit 2107f7d
Showing 1 changed file with 4 additions and 8 deletions.
Expand Up @@ -82,7 +82,7 @@ func NewProxyHandler(
appRegistryHost: appRegistryHost,

eventsProxy: createReverseProxy(eventServiceHost),
eventMeshProxy: createReverseProxy(eventMeshHost, withRewriteBaseURL("/"), withEnforceURLHost),
eventMeshProxy: createReverseProxy(eventMeshHost, withRewriteBaseURL("/")),
appRegistryProxy: createReverseProxy(appRegistryHost),

applicationGetter: applicationGetter,
Expand Down Expand Up @@ -295,7 +295,8 @@ func createReverseProxy(destinationHost string, reqOpts ...requestOption) *httpu
Director: func(request *http.Request) {
request.URL.Scheme = "http"
request.URL.Host = destinationHost

request.Host = ""
delete(request.Header, "X-Forwarded-Client-Cert")
for _, opt := range reqOpts {
opt(request)
}
Expand All @@ -304,6 +305,7 @@ func createReverseProxy(destinationHost string, reqOpts ...requestOption) *httpu
},
ModifyResponse: func(response *http.Response) error {
log.Infof("Host responded with status: %s", response.Status)

return nil
},
}
Expand All @@ -317,9 +319,3 @@ func withRewriteBaseURL(path string) requestOption {
req.URL.Path = path
}
}

// withEnforceURLHost enforces the Request's Host field to be empty to ensure
// the 'Host' HTTP header is set to the host name defined in the Request's URL.
func withEnforceURLHost(req *http.Request) {
req.Host = ""
}

0 comments on commit 2107f7d

Please sign in to comment.