Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
449e4b2c
Commit
449e4b2c
authored
Feb 02, 2015
by
Alex Robinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4038 from enisoc/apiserver-proxy-rewrite
Fix apiserver proxy path rewriting.
parents
a5a53025
695b0888
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
11 deletions
+29
-11
proxy.go
pkg/apiserver/proxy.go
+18
-8
proxy_test.go
pkg/apiserver/proxy_test.go
+11
-3
No files found.
pkg/apiserver/proxy.go
View file @
449e4b2c
...
@@ -216,16 +216,26 @@ func (t *proxyTransport) updateURLs(n *html.Node, sourceURL *url.URL) {
...
@@ -216,16 +216,26 @@ func (t *proxyTransport) updateURLs(n *html.Node, sourceURL *url.URL) {
if
err
!=
nil
{
if
err
!=
nil
{
continue
continue
}
}
// Is this URL relative?
if
url
.
Host
==
""
{
// Is this URL referring to the same host as sourceURL?
url
.
Scheme
=
t
.
proxyScheme
if
url
.
Host
==
""
||
url
.
Host
==
sourceURL
.
Host
{
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
.
Scheme
=
t
.
proxyScheme
url
.
Host
=
t
.
proxyHost
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
()
n
.
Attr
[
i
]
.
Val
=
url
.
String
()
}
}
}
}
...
...
pkg/apiserver/proxy_test.go
View file @
449e4b2c
...
@@ -76,7 +76,15 @@ func TestProxyTransport(t *testing.T) {
...
@@ -76,7 +76,15 @@ func TestProxyTransport(t *testing.T) {
input
:
`<pre><a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a></pre>`
,
input
:
`<pre><a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a></pre>`
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
transport
:
testTransport
,
transport
:
testTransport
,
output
:
`<pre><a href="http://foo.com/proxy/minion/minion1:10250/logs/kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/logs/google.log">google.log</a></pre>`
,
output
:
`<pre><a href="http://foo.com/proxy/minion/minion1:10250/logs/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"
,
},
"trailing slash"
:
{
input
:
`<pre><a href="kubelet.log">kubelet.log</a><a href="/google.log/">google.log</a></pre>`
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
transport
:
testTransport
,
output
:
`<pre><a href="http://foo.com/proxy/minion/minion1:10250/logs/kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/google.log/">google.log</a></pre>`
,
contentType
:
"text/html"
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
},
...
@@ -84,7 +92,7 @@ func TestProxyTransport(t *testing.T) {
...
@@ -84,7 +92,7 @@ func TestProxyTransport(t *testing.T) {
input
:
`<pre><a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a></pre>`
,
input
:
`<pre><a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a></pre>`
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
transport
:
testTransport
,
transport
:
testTransport
,
output
:
`<pre><a href="http://foo.com/proxy/minion/minion1:10250/logs/kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/
logs/
google.log">google.log</a></pre>`
,
output
:
`<pre><a href="http://foo.com/proxy/minion/minion1:10250/logs/kubelet.log">kubelet.log</a><a href="http://foo.com/proxy/minion/minion1:10250/google.log">google.log</a></pre>`
,
contentType
:
"text/html; charset=utf-8"
,
contentType
:
"text/html; charset=utf-8"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
},
...
@@ -100,7 +108,7 @@ func TestProxyTransport(t *testing.T) {
...
@@ -100,7 +108,7 @@ func TestProxyTransport(t *testing.T) {
input
:
`<a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a>`
,
input
:
`<a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a>`
,
sourceURL
:
"http://myminion.com/whatever/apt/somelog.log"
,
sourceURL
:
"http://myminion.com/whatever/apt/somelog.log"
,
transport
:
testTransport2
,
transport
:
testTransport2
,
output
:
`<a href="https://foo.com/proxy/minion/minion1:8080/whatever/apt/kubelet.log">kubelet.log</a><a href="https://foo.com/proxy/minion/minion1:8080/
whatever/apt/
google.log">google.log</a>`
,
output
:
`<a href="https://foo.com/proxy/minion/minion1:8080/whatever/apt/kubelet.log">kubelet.log</a><a href="https://foo.com/proxy/minion/minion1:8080/google.log">google.log</a>`
,
contentType
:
"text/html"
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:8080/whatever/apt/somelog.log"
,
forwardedURI
:
"/proxy/minion/minion1:8080/whatever/apt/somelog.log"
,
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment