mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Fix apiserver proxy path rewriting.
1) Absolute paths without a hostname were being rewritten relative to the current page, rather than relative to the current host. e.g. When viewing /some/page.html, it would rewrite: /other/page.html => proxyPrepend/some/other/page.html Instead, it should rewrite: /other/page.html => proxyPrepend/other/page.html 2) Trailing slashes were being stripped from all rewritten URLs. This is because path.Join() always calls path.Clean() as well: http://golang.org/pkg/path/#Join
This commit is contained in:
@@ -216,16 +216,26 @@ func (t *proxyTransport) updateURLs(n *html.Node, sourceURL *url.URL) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// Is this URL relative?
|
||||
if url.Host == "" {
|
||||
|
||||
// Is this URL referring to the same host as sourceURL?
|
||||
if url.Host == "" || url.Host == sourceURL.Host {
|
||||
url.Scheme = t.proxyScheme
|
||||
url.Host = t.proxyHost
|
||||
url.Path = path.Join(t.proxyPathPrepend, path.Dir(sourceURL.Path), url.Path, "/")
|
||||
n.Attr[i].Val = url.String()
|
||||
} else if url.Host == sourceURL.Host {
|
||||
url.Scheme = t.proxyScheme
|
||||
url.Host = t.proxyHost
|
||||
url.Path = path.Join(t.proxyPathPrepend, url.Path)
|
||||
origPath := url.Path
|
||||
|
||||
if strings.HasPrefix(url.Path, "/") {
|
||||
// The path is rooted at the host. Just add proxy prepend.
|
||||
url.Path = path.Join(t.proxyPathPrepend, url.Path)
|
||||
} else {
|
||||
// The path is relative to sourceURL.
|
||||
url.Path = path.Join(t.proxyPathPrepend, path.Dir(sourceURL.Path), url.Path)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(origPath, "/") {
|
||||
// Add back the trailing slash, which was stripped by path.Join().
|
||||
url.Path += "/"
|
||||
}
|
||||
|
||||
n.Attr[i].Val = url.String()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user