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
746aae4c
Commit
746aae4c
authored
Oct 16, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15784 from csrwng/remove_blank_proxy_headers
Auto commit by PR queue bot
parents
35e4c640
b56d4741
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 @
746aae4c
...
@@ -86,8 +86,12 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
...
@@ -86,8 +86,12 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
forwardedURI
=
forwardedURI
+
"/"
forwardedURI
=
forwardedURI
+
"/"
}
}
req
.
Header
.
Set
(
"X-Forwarded-Uri"
,
forwardedURI
)
req
.
Header
.
Set
(
"X-Forwarded-Uri"
,
forwardedURI
)
req
.
Header
.
Set
(
"X-Forwarded-Host"
,
t
.
Host
)
if
len
(
t
.
Host
)
>
0
{
req
.
Header
.
Set
(
"X-Forwarded-Proto"
,
t
.
Scheme
)
req
.
Header
.
Set
(
"X-Forwarded-Host"
,
t
.
Host
)
}
if
len
(
t
.
Scheme
)
>
0
{
req
.
Header
.
Set
(
"X-Forwarded-Proto"
,
t
.
Scheme
)
}
rt
:=
t
.
RoundTripper
rt
:=
t
.
RoundTripper
if
rt
==
nil
{
if
rt
==
nil
{
...
...
pkg/util/proxy/transport_test.go
View file @
746aae4c
...
@@ -45,6 +45,14 @@ func TestProxyTransport(t *testing.T) {
...
@@ -45,6 +45,14 @@ func TestProxyTransport(t *testing.T) {
Host
:
"foo.com"
,
Host
:
"foo.com"
,
PathPrepend
:
"/proxy/minion/minion1:8080"
,
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
{
type
Item
struct
{
input
string
input
string
sourceURL
string
sourceURL
string
...
@@ -158,6 +166,22 @@ func TestProxyTransport(t *testing.T) {
...
@@ -158,6 +166,22 @@ func TestProxyTransport(t *testing.T) {
contentType
:
"text/html"
,
contentType
:
"text/html"
,
forwardedURI
:
"/proxy/minion/minion1:10250/logs/log.log"
,
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
)
{
testItem
:=
func
(
name
string
,
item
*
Item
)
{
...
@@ -166,11 +190,25 @@ func TestProxyTransport(t *testing.T) {
...
@@ -166,11 +190,25 @@ func TestProxyTransport(t *testing.T) {
if
got
,
want
:=
r
.
Header
.
Get
(
"X-Forwarded-Uri"
),
item
.
forwardedURI
;
got
!=
want
{
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
)
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
{
if
len
(
item
.
transport
.
Host
)
==
0
{
t
.
Errorf
(
"%v: X-Forwarded-Host = %q, want %q"
,
name
,
got
,
want
)
_
,
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
{
if
len
(
item
.
transport
.
Scheme
)
==
0
{
t
.
Errorf
(
"%v: X-Forwarded-Proto = %q, want %q"
,
name
,
got
,
want
)
_
,
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.
// 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