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
fd7d46e9
Commit
fd7d46e9
authored
Jun 12, 2015
by
Tim St. Clair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't rewrite relative URLs when proxying HTTP content.
parent
921011fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
19 deletions
+14
-19
transport.go
pkg/util/proxy/transport.go
+8
-13
transport_test.go
pkg/util/proxy/transport_test.go
+6
-6
No files found.
pkg/util/proxy/transport.go
View file @
fd7d46e9
...
...
@@ -119,21 +119,17 @@ func (t *Transport) rewriteURL(targetURL string, sourceURL *url.URL) string {
if
err
!=
nil
{
return
targetURL
}
if
url
.
Host
!=
""
&&
url
.
Host
!=
sourceURL
.
Host
{
isDifferentHost
:=
url
.
Host
!=
""
&&
url
.
Host
!=
sourceURL
.
Host
isRelative
:=
!
strings
.
HasPrefix
(
url
.
Path
,
"/"
)
if
isDifferentHost
||
isRelative
{
return
targetURL
}
url
.
Scheme
=
t
.
Scheme
url
.
Host
=
t
.
Host
origPath
:=
url
.
Path
if
strings
.
HasPrefix
(
url
.
Path
,
"/"
)
{
// The path is rooted at the host. Just add proxy prepend.
url
.
Path
=
path
.
Join
(
t
.
PathPrepend
,
url
.
Path
)
}
else
{
// The path is relative to sourceURL.
url
.
Path
=
path
.
Join
(
t
.
PathPrepend
,
path
.
Dir
(
sourceURL
.
Path
),
url
.
Path
)
}
url
.
Path
=
path
.
Join
(
t
.
PathPrepend
,
url
.
Path
)
if
strings
.
HasSuffix
(
origPath
,
"/"
)
{
// Add back the trailing slash, which was stripped by path.Join().
...
...
@@ -144,10 +140,9 @@ func (t *Transport) rewriteURL(targetURL string, sourceURL *url.URL) string {
}
// updateURLs checks and updates any of n's attributes that are listed in tagsToAttrs.
// Any URLs found are, if they're relative, updated with the necessary changes to make
// a visit to that URL also go through the proxy.
// sourceURL is the URL of the page which we're currently on; it's required to make
// relative links work.
// Any URLs found are, if they share the source host, updated with the necessary changes
// to make a visit to that URL also go through the proxy.
// sourceURL is the URL of the page which we're currently on.
func
(
t
*
Transport
)
updateURLs
(
n
*
html
.
Node
,
sourceURL
*
url
.
URL
)
{
if
n
.
Type
!=
html
.
ElementNode
{
return
...
...
pkg/util/proxy/transport_test.go
View file @
fd7d46e9
...
...
@@ -77,7 +77,7 @@ func TestProxyTransport(t *testing.T) {
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>`
,
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"
,
},
...
...
@@ -85,7 +85,7 @@ func TestProxyTransport(t *testing.T) {
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>`
,
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"
,
},
...
...
@@ -93,7 +93,7 @@ func TestProxyTransport(t *testing.T) {
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>`
,
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; charset=utf-8"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
...
...
@@ -109,15 +109,15 @@ func TestProxyTransport(t *testing.T) {
input
:
`<a href="kubelet.log">kubelet.log</a><a href="/google.log">google.log</a>`
,
sourceURL
:
"http://myminion.com/whatever/apt/somelog.log"
,
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/google.log">google.log</a>`
,
output
:
`<a href="kubelet.log">kubelet.log</a><a href="https://foo.com/proxy/minion/minion1:8080/google.log">google.log</a>`
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:8080/whatever/apt/somelog.log"
,
},
"image"
:
{
input
:
`<pre><img src="kubernetes.jpg"/></pre>`
,
input
:
`<pre><img src="kubernetes.jpg"/><
img src="/kubernetes_abs.jpg"/><
/pre>`
,
sourceURL
:
"http://myminion.com/"
,
transport
:
testTransport
,
output
:
`<pre><img src="
http://foo.com/proxy/minion/minion1:10250/kubernete
s.jpg"/></pre>`
,
output
:
`<pre><img src="
kubernetes.jpg"/><img src="http://foo.com/proxy/minion/minion1:10250/kubernetes_ab
s.jpg"/></pre>`
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/"
,
},
...
...
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