Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
32329a47
Commit
32329a47
authored
Jun 29, 2016
by
Matt Holt
Committed by
GitHub
Jun 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #909 from evermax/master
Test that the host header forwarding on proxy
parents
6db4771a
e5bf8cab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletion
+67
-1
caddyhttp/proxy/policy_test.go
caddyhttp/proxy/policy_test.go
+1
-1
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+66
-0
No files found.
caddyhttp/proxy/policy_test.go
View file @
32329a47
...
...
@@ -31,7 +31,7 @@ func testPool() HostPool {
Name
:
workableServer
.
URL
,
// this should resolve (healthcheck test)
},
{
Name
:
"http://
shouldnot.resolve
"
,
// this shouldn't
Name
:
"http://
localhost:99998
"
,
// this shouldn't
},
{
Name
:
"http://C"
,
...
...
caddyhttp/proxy/proxy_test.go
View file @
32329a47
...
...
@@ -576,6 +576,72 @@ func TestMultiReverseProxyFromClient(t *testing.T) {
}
}
func
TestHostSimpleProxyNoHeaderForward
(
t
*
testing
.
T
)
{
var
requestHost
string
backend
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
requestHost
=
r
.
Host
w
.
Write
([]
byte
(
"Hello, client"
))
}))
defer
backend
.
Close
()
// set up proxy
p
:=
&
Proxy
{
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Upstreams
:
[]
Upstream
{
newFakeUpstream
(
backend
.
URL
,
false
)},
}
r
,
err
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
.
Host
=
"test.com"
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create request: %v"
,
err
)
}
w
:=
httptest
.
NewRecorder
()
p
.
ServeHTTP
(
w
,
r
)
if
!
strings
.
Contains
(
backend
.
URL
,
"//"
)
{
t
.
Fatalf
(
"The URL of the backend server doesn't contains //: %s"
,
backend
.
URL
)
}
expectedHost
:=
strings
.
Split
(
backend
.
URL
,
"//"
)
if
expectedHost
[
1
]
!=
requestHost
{
t
.
Fatalf
(
"Expected %s as a Host header got %s
\n
"
,
expectedHost
[
1
],
requestHost
)
}
}
func
TestHostHeaderReplacedUsingForward
(
t
*
testing
.
T
)
{
var
requestHost
string
backend
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
requestHost
=
r
.
Host
w
.
Write
([]
byte
(
"Hello, client"
))
}))
defer
backend
.
Close
()
upstream
:=
newFakeUpstream
(
backend
.
URL
,
false
)
proxyHostHeader
:=
"test2.com"
upstream
.
host
.
UpstreamHeaders
=
http
.
Header
{
"Host"
:
[]
string
{
proxyHostHeader
}}
// set up proxy
p
:=
&
Proxy
{
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Upstreams
:
[]
Upstream
{
upstream
},
}
r
,
err
:=
http
.
NewRequest
(
"GET"
,
"/"
,
nil
)
r
.
Host
=
"test.com"
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create request: %v"
,
err
)
}
w
:=
httptest
.
NewRecorder
()
p
.
ServeHTTP
(
w
,
r
)
if
proxyHostHeader
!=
requestHost
{
t
.
Fatalf
(
"Expected %s as a Host header got %s
\n
"
,
proxyHostHeader
,
requestHost
)
}
}
func
newFakeUpstream
(
name
string
,
insecure
bool
)
*
fakeUpstream
{
uri
,
_
:=
url
.
Parse
(
name
)
u
:=
&
fakeUpstream
{
...
...
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