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
b56d4741
Commit
b56d4741
authored
Oct 16, 2015
by
Cesar Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proxy: do not send X-Forwarded-Host or X-Forwarded-Proto with an empty value
parent
a6634adc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
6 deletions
+48
-6
transport.go
pkg/util/proxy/transport.go
+6
-2
transport_test.go
pkg/util/proxy/transport_test.go
+42
-4
No files found.
pkg/util/proxy/transport.go
View file @
b56d4741
...
...
@@ -86,8 +86,12 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
forwardedURI
=
forwardedURI
+
"/"
}
req
.
Header
.
Set
(
"X-Forwarded-Uri"
,
forwardedURI
)
req
.
Header
.
Set
(
"X-Forwarded-Host"
,
t
.
Host
)
req
.
Header
.
Set
(
"X-Forwarded-Proto"
,
t
.
Scheme
)
if
len
(
t
.
Host
)
>
0
{
req
.
Header
.
Set
(
"X-Forwarded-Host"
,
t
.
Host
)
}
if
len
(
t
.
Scheme
)
>
0
{
req
.
Header
.
Set
(
"X-Forwarded-Proto"
,
t
.
Scheme
)
}
rt
:=
t
.
RoundTripper
if
rt
==
nil
{
...
...
pkg/util/proxy/transport_test.go
View file @
b56d4741
...
...
@@ -45,6 +45,14 @@ func TestProxyTransport(t *testing.T) {
Host
:
"foo.com"
,
PathPrepend
:
"/proxy/minion/minion1:8080"
,
}
emptyHostTransport
:=
&
Transport
{
Scheme
:
"https"
,
PathPrepend
:
"/proxy/minion/minion1:10250"
,
}
emptySchemeTransport
:=
&
Transport
{
Host
:
"foo.com"
,
PathPrepend
:
"/proxy/minion/minion1:10250"
,
}
type
Item
struct
{
input
string
sourceURL
string
...
...
@@ -158,6 +166,22 @@ func TestProxyTransport(t *testing.T) {
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
"no host"
:
{
input
:
"<html></html>"
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
transport
:
emptyHostTransport
,
output
:
"<html></html>"
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
"no scheme"
:
{
input
:
"<html></html>"
,
sourceURL
:
"http://myminion.com/logs/log.log"
,
transport
:
emptySchemeTransport
,
output
:
"<html></html>"
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
},
}
testItem
:=
func
(
name
string
,
item
*
Item
)
{
...
...
@@ -166,11 +190,25 @@ func TestProxyTransport(t *testing.T) {
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Uri"
),
item
.
forwardedURI
;
got
!=
want
{
t
.
Errorf
(
"%v: X-Forwarded-Uri = %q, want %q"
,
name
,
got
,
want
)
}
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Host"
),
item
.
transport
.
Host
;
got
!=
want
{
t
.
Errorf
(
"%v: X-Forwarded-Host = %q, want %q"
,
name
,
got
,
want
)
if
len
(
item
.
transport
.
Host
)
==
0
{
_
,
present
:=
r
.
Header
[
"X-Forwarded-Host"
]
if
present
{
t
.
Errorf
(
"%v: X-Forwarded-Host header should not be present"
,
name
)
}
}
else
{
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Host"
),
item
.
transport
.
Host
;
got
!=
want
{
t
.
Errorf
(
"%v: X-Forwarded-Host = %q, want %q"
,
name
,
got
,
want
)
}
}
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Proto"
),
item
.
transport
.
Scheme
;
got
!=
want
{
t
.
Errorf
(
"%v: X-Forwarded-Proto = %q, want %q"
,
name
,
got
,
want
)
if
len
(
item
.
transport
.
Scheme
)
==
0
{
_
,
present
:=
r
.
Header
[
"X-Forwarded-Proto"
]
if
present
{
t
.
Errorf
(
"%v: X-Forwarded-Proto header should not be present"
,
name
)
}
}
else
{
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Proto"
),
item
.
transport
.
Scheme
;
got
!=
want
{
t
.
Errorf
(
"%v: X-Forwarded-Proto = %q, want %q"
,
name
,
got
,
want
)
}
}
// Send response.
...
...
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