Updating proxy to return 301 to add a / at the end

This commit is contained in:
nikhiljindal
2015-03-27 00:47:05 -07:00
parent a2801a5a18
commit 2fff606a6f
2 changed files with 65 additions and 0 deletions

View File

@@ -191,6 +191,15 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
// Redirect requests of the form "/{resource}/{name}" to "/{resource}/{name}/"
// This is essentially a hack for https://github.com/GoogleCloudPlatform/kubernetes/issues/4958.
// Note: Keep this code after tryUpgrade to not break that flow.
if len(parts) == 2 && !strings.HasSuffix(req.URL.Path, "/") {
w.Header().Set("Location", req.URL.Path+"/")
w.WriteHeader(http.StatusMovedPermanently)
return
}
proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: location.Scheme, Host: location.Host})
if transport == nil {
prepend := path.Join(r.prefix, resource, id)