From 44b23c8e3e36849ce5fe1e9ae818dc078cb6cf70 Mon Sep 17 00:00:00 2001 From: Dominic Black Date: Wed, 12 Jul 2023 18:21:38 +0100 Subject: [PATCH] Don't rewrite Host in Gateway proxy (#799) 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. --- runtime/appruntime/apisdk/api/gateway.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/appruntime/apisdk/api/gateway.go b/runtime/appruntime/apisdk/api/gateway.go index 5be3c94bc6..d4bb3e3e8e 100644 --- a/runtime/appruntime/apisdk/api/gateway.go +++ b/runtime/appruntime/apisdk/api/gateway.go @@ -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) { @@ -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