Fix proxying of URLs that end in "/" in the pod proxy subresource

Also handles proxying of URLs that have an empty path and don't end in a slash "/" by redirecting to the same location with a slash appended.
This commit is contained in:
Cesar Wong
2015-05-27 21:05:07 +00:00
parent b7caedeedb
commit 684dcd4307
3 changed files with 110 additions and 12 deletions

View File

@@ -77,7 +77,11 @@ type Transport struct {
// RoundTrip implements the http.RoundTripper interface
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
// Add reverse proxy headers.
req.Header.Set("X-Forwarded-Uri", t.PathPrepend+req.URL.Path)
forwardedURI := path.Join(t.PathPrepend, req.URL.Path)
if strings.HasSuffix(req.URL.Path, "/") {
forwardedURI = forwardedURI + "/"
}
req.Header.Set("X-Forwarded-Uri", forwardedURI)
req.Header.Set("X-Forwarded-Host", t.Host)
req.Header.Set("X-Forwarded-Proto", t.Scheme)