diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index 879a88819fb..af734f7f7f7 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -113,10 +113,16 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { location, err := redirector.ResourceLocation(ctx, id) if err != nil { + httplog.LogOf(req, w).Addf("Error getting ResourceLocation: %v", err) status := errToAPIStatus(err) writeJSON(status.Code, r.codec, status, w) return } + if location == "" { + httplog.LogOf(req, w).Addf("ResourceLocation for %v returned ''", id) + notFound(w, req) + return + } destURL, err := url.Parse(location) if err != nil { @@ -124,11 +130,19 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { writeJSON(status.Code, r.codec, status, w) 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.RawQuery = req.URL.RawQuery newReq, err := http.NewRequest(req.Method, destURL.String(), req.Body) 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