diff --git a/internal/runnerfacade/facade_test.go b/internal/runnerfacade/facade_test.go index 87e6d66..6300842 100644 --- a/internal/runnerfacade/facade_test.go +++ b/internal/runnerfacade/facade_test.go @@ -7,6 +7,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "strings" "testing" "connectrpc.com/connect" @@ -131,9 +132,11 @@ func TestAPIHandlerMatchesOfficialRunnerBasePath(t *testing.T) { } func TestHandlerProxiesRepositoryTrafficToGitea(t *testing.T) { - upstream := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { - if request.URL.Path != "/owner/repo/info/refs" || request.Header.Get("Authorization") != "Basic checkout-token" { - t.Errorf("request path=%q authorization=%q", request.URL.Path, request.Header.Get("Authorization")) + var upstream *httptest.Server + upstream = httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { + upstreamHost := strings.TrimPrefix(upstream.URL, "http://") + if request.URL.Path != "/owner/repo/info/refs" || request.Header.Get("Authorization") != "Basic checkout-token" || request.Host != upstreamHost { + t.Errorf("request path=%q authorization=%q host=%q", request.URL.Path, request.Header.Get("Authorization"), request.Host) response.WriteHeader(http.StatusBadRequest) return } diff --git a/internal/runnerfacade/server.go b/internal/runnerfacade/server.go index 95384c7..ecccca1 100644 --- a/internal/runnerfacade/server.go +++ b/internal/runnerfacade/server.go @@ -39,7 +39,13 @@ func Handler(facade *Facade, upstreamURL string) (http.Handler, error) { path, service := facade.Handler() mux := http.NewServeMux() mux.Handle(APIBasePath+path, http.StripPrefix(APIBasePath, SPIFFEMiddleware(service))) - mux.Handle("/", httputil.NewSingleHostReverseProxy(target)) + proxy := httputil.NewSingleHostReverseProxy(target) + director := proxy.Director + proxy.Director = func(request *http.Request) { + director(request) + request.Host = target.Host + } + mux.Handle("/", proxy) return mux, nil }