From 2788b470597719a574ffe092819401814587b074 Mon Sep 17 00:00:00 2001 From: Vishnu kannan Date: Mon, 28 Sep 2015 16:42:34 -0700 Subject: [PATCH] Avoid rewriting URLs in the proxy, if the application is proxy-aware. --- pkg/util/proxy/transport.go | 5 ++++- pkg/util/proxy/transport_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/util/proxy/transport.go b/pkg/util/proxy/transport.go index ca88147752d..80855f46b8b 100644 --- a/pkg/util/proxy/transport.go +++ b/pkg/util/proxy/transport.go @@ -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 += "/" diff --git a/pkg/util/proxy/transport_test.go b/pkg/util/proxy/transport_test.go index 4f5fb01ced9..0e444f9ab5d 100644 --- a/pkg/util/proxy/transport_test.go +++ b/pkg/util/proxy/transport_test.go @@ -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: `
kubelet.loggoogle.log
`, + sourceURL: "http://foo.com/logs/log.log", + transport: testTransport, + output: `
kubelet.loggoogle.log
`, + contentType: "text/html", + forwardedURI: "/proxy/minion/minion1:10250/logs/log.log", + }, } testItem := func(name string, item *Item) {