Merge pull request #72689 from KevinKingKong/fix_aggregator_bug

Fix aggregator bug
This commit is contained in:
Kubernetes Prow Robot 2019-01-29 06:57:18 -08:00 committed by GitHub
commit 7f82a231ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -142,6 +142,7 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
newReq := req.WithContext(context.Background()) newReq := req.WithContext(context.Background())
newReq.Header = utilnet.CloneHeader(req.Header) newReq.Header = utilnet.CloneHeader(req.Header)
newReq.URL = location newReq.URL = location
newReq.Host = location.Host
if handlingInfo.proxyRoundTripper == nil { if handlingInfo.proxyRoundTripper == nil {
proxyError(w, req, "", http.StatusNotFound) proxyError(w, req, "", http.StatusNotFound)

View File

@ -42,18 +42,21 @@ type targetHTTPHandler struct {
called bool called bool
headers map[string][]string headers map[string][]string
path string path string
host string
} }
func (d *targetHTTPHandler) Reset() { func (d *targetHTTPHandler) Reset() {
d.path = "" d.path = ""
d.called = false d.called = false
d.headers = nil d.headers = nil
d.host = ""
} }
func (d *targetHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (d *targetHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
d.path = r.URL.Path d.path = r.URL.Path
d.called = true d.called = true
d.headers = r.Header d.headers = r.Header
d.host = r.Host
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
@ -313,6 +316,10 @@ func TestProxyHandler(t *testing.T) {
t.Errorf("%s: expected %v, got %v", name, e, a) t.Errorf("%s: expected %v, got %v", name, e, a)
return 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
}
}() }()
} }
} }