Skip to content

Commit

Permalink
Don't rewrite Host in Gateway proxy (#799)
Browse files Browse the repository at this point in the history
Previously we where rewriting the HTTP `Host` header in the proxy to
preserve the original host information - which would allow Encore to
perform Host based switching behaviour in downstream services.

However this breaks in CloudRun as the load balancers will then end up
rerouting the request back to the proxy - causing an infinite recursion
of calls.
  • Loading branch information
DomBlack authored Jul 12, 2023
1 parent 266bce3 commit 44b23c8
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions runtime/appruntime/apisdk/api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Server) createGatewayHandlerAdapter(h Handler) httprouter.Handle {

// On cloud environments, we want to log the proxying of requests to services
// but locally we don't want the overhead of logging every request.
logger := s.rootLogger.With().Str("service", service.Name).Str("endpoint", h.EndpointName()).Logger()
logger := s.rootLogger.With().Str("service", service.Name).Str("endpoint", h.EndpointName()).Str("base_url", serviceBaseURL.String()).Logger()

proxy := s.createProxyToService(service, h.EndpointName(), serviceBaseURL, logger)
return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
Expand Down Expand Up @@ -73,7 +73,6 @@ func (s *Server) createProxyToService(service config.Service, endpointName strin
// Rewrite the inbound request
Rewrite: func(req *httputil.ProxyRequest) {
req.SetURL(serviceBaseURL)
req.Out.Host = req.In.Host

t := transport.HTTPRequest(req.Out)
t.SetMeta(calleeMetaName, callee) // required by the Handler which verifies we wanted to call this endpoint
Expand Down

0 comments on commit 44b23c8

Please sign in to comment.