mirror of https://github.com/k3s-io/k3s
Merge pull request #14697 from vishh/api-proxy
Avoid rewriting URLs in the proxy, if the application is proxy-aware.pull/6/head
commit
a448b5e154
|
@ -136,8 +136,11 @@ func (t *Transport) rewriteURL(targetURL string, sourceURL *url.URL) string {
|
|||
url.Scheme = t.Scheme
|
||||
url.Host = t.Host
|
||||
origPath := url.Path
|
||||
// Do not rewrite URL if the sourceURL already contains the necessary prefix.
|
||||
if strings.HasPrefix(url.Path, t.PathPrepend) {
|
||||
return url.String()
|
||||
}
|
||||
url.Path = path.Join(t.PathPrepend, url.Path)
|
||||
|
||||
if strings.HasSuffix(origPath, "/") {
|
||||
// Add back the trailing slash, which was stripped by path.Join().
|
||||
url.Path += "/"
|
||||
|
|
|
@ -150,6 +150,14 @@ func TestProxyTransport(t *testing.T) {
|
|||
redirectWant: "http://example.com/redirected/target/",
|
||||
forwardedURI: "/proxy/minion/minion1:10250/redirect",
|
||||
},
|
||||
"source contains the redirect already": {
|
||||
input: `<pre><a href="kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/google.log">google.log</a></pre>`,
|
||||
sourceURL: "http://foo.com/logs/log.log",
|
||||
transport: testTransport,
|
||||
output: `<pre><a href="kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/google.log">google.log</a></pre>`,
|
||||
contentType: "text/html",
|
||||
forwardedURI: "/proxy/minion/minion1:10250/logs/log.log",
|
||||
},
|
||||
}
|
||||
|
||||
testItem := func(name string, item *Item) {
|
||||
|
|
Loading…
Reference in New Issue