mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Fix subtle bug when proxy constructs outgoing URL.
This commit is contained in:
parent
7209ca1543
commit
3045311398
@ -113,10 +113,16 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
location, err := redirector.ResourceLocation(ctx, id)
|
location, err := redirector.ResourceLocation(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
httplog.LogOf(req, w).Addf("Error getting ResourceLocation: %v", err)
|
||||||
status := errToAPIStatus(err)
|
status := errToAPIStatus(err)
|
||||||
writeJSON(status.Code, r.codec, status, w)
|
writeJSON(status.Code, r.codec, status, w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if location == "" {
|
||||||
|
httplog.LogOf(req, w).Addf("ResourceLocation for %v returned ''", id)
|
||||||
|
notFound(w, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
destURL, err := url.Parse(location)
|
destURL, err := url.Parse(location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -124,11 +130,19 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
writeJSON(status.Code, r.codec, status, w)
|
writeJSON(status.Code, r.codec, status, w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if destURL.Scheme == "" {
|
||||||
|
// If no scheme was present in location, url.Parse sometimes mistakes
|
||||||
|
// hosts for paths.
|
||||||
|
destURL.Host = location
|
||||||
|
}
|
||||||
destURL.Path = rest
|
destURL.Path = rest
|
||||||
destURL.RawQuery = req.URL.RawQuery
|
destURL.RawQuery = req.URL.RawQuery
|
||||||
newReq, err := http.NewRequest(req.Method, destURL.String(), req.Body)
|
newReq, err := http.NewRequest(req.Method, destURL.String(), req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create request: %s", err)
|
status := errToAPIStatus(err)
|
||||||
|
writeJSON(status.Code, r.codec, status, w)
|
||||||
|
notFound(w, req)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
newReq.Header = req.Header
|
newReq.Header = req.Header
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user