Add URL parameters to proxy redirect Location header

When a URL that doesn't end in "/" is sent to the API proxy,
the proxy responds with a redirect to the URL with a "/" at the
end. The problem is that this redirect path does not include
query parameters that were passed in the original request. This
is a fix to that issue.
This commit is contained in:
Cesar Wong
2015-04-16 17:24:01 -04:00
parent 0fc94155cf
commit e09b8c99dc
2 changed files with 15 additions and 6 deletions

View File

@@ -195,7 +195,11 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// 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+"/")
var queryPart string
if len(req.URL.RawQuery) > 0 {
queryPart = "?" + req.URL.RawQuery
}
w.Header().Set("Location", req.URL.Path+"/"+queryPart)
w.WriteHeader(http.StatusMovedPermanently)
return
}