diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go index e6e30bbd44b..ee3433212c6 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go @@ -142,6 +142,7 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { newReq := req.WithContext(context.Background()) newReq.Header = utilnet.CloneHeader(req.Header) newReq.URL = location + newReq.Host = location.Host if handlingInfo.proxyRoundTripper == nil { proxyError(w, req, "", http.StatusNotFound) diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go index 354c8d8b94a..b4ed4b77bdc 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go @@ -42,18 +42,21 @@ type targetHTTPHandler struct { called bool headers map[string][]string path string + host string } func (d *targetHTTPHandler) Reset() { d.path = "" d.called = false d.headers = nil + d.host = "" } func (d *targetHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { d.path = r.URL.Path d.called = true d.headers = r.Header + d.host = r.Host w.WriteHeader(http.StatusOK) } @@ -313,6 +316,10 @@ func TestProxyHandler(t *testing.T) { t.Errorf("%s: expected %v, got %v", name, e, a) return } + if e, a := targetServer.Listener.Addr().String(), target.host; tc.expectedCalled && !reflect.DeepEqual(e, a) { + t.Errorf("%s: expected %v, got %v", name, e, a) + return + } }() } }