mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-22 18:16:52 +00:00
fix apiserver aggregator bug
This commit is contained in:
parent
8743a0e3c6
commit
120570b3fb
@ -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)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +261,38 @@ func TestProxyHandler(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedStatusCode: http.StatusServiceUnavailable,
|
expectedStatusCode: http.StatusServiceUnavailable,
|
||||||
},
|
},
|
||||||
|
"change aggregator http request host": {
|
||||||
|
user: &user.DefaultInfo{
|
||||||
|
Name: "username",
|
||||||
|
Groups: []string{"one", "two"},
|
||||||
|
},
|
||||||
|
path: "/request/path",
|
||||||
|
apiService: &apiregistration.APIService{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "v1.foo"},
|
||||||
|
Spec: apiregistration.APIServiceSpec{
|
||||||
|
Service: &apiregistration.ServiceReference{},
|
||||||
|
Group: "foo",
|
||||||
|
Version: "v1",
|
||||||
|
InsecureSkipTLSVerify: true,
|
||||||
|
},
|
||||||
|
Status: apiregistration.APIServiceStatus{
|
||||||
|
Conditions: []apiregistration.APIServiceCondition{
|
||||||
|
{Type: apiregistration.Available, Status: apiregistration.ConditionTrue},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedStatusCode: http.StatusOK,
|
||||||
|
expectedCalled: true,
|
||||||
|
expectedHeaders: map[string][]string{
|
||||||
|
"X-Forwarded-Proto": {"https"},
|
||||||
|
"X-Forwarded-Uri": {"/request/path"},
|
||||||
|
"X-Forwarded-For": {"127.0.0.1"},
|
||||||
|
"X-Remote-User": {"username"},
|
||||||
|
"User-Agent": {"Go-http-client/1.1"},
|
||||||
|
"Accept-Encoding": {"gzip"},
|
||||||
|
"X-Remote-Group": {"one", "two"},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, tc := range tests {
|
for name, tc := range tests {
|
||||||
@ -313,6 +348,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
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user