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
Łukasz Nowak
caddy
Commits
c6c221b8
Commit
c6c221b8
authored
Aug 05, 2016
by
Matt Holt
Committed by
GitHub
Aug 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #996 from tw4452852/host_header
proxy: add Host header checking
parents
985049e0
94c63e42
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+9
-0
No files found.
caddyhttp/proxy/proxy_test.go
View file @
c6c221b8
...
...
@@ -357,9 +357,11 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
defer
log
.
SetOutput
(
os
.
Stderr
)
var
actualHeaders
http
.
Header
var
actualHost
string
backend
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
([]
byte
(
"Hello, client"
))
actualHeaders
=
r
.
Header
actualHost
=
r
.
Host
}))
defer
backend
.
Close
()
...
...
@@ -371,6 +373,7 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
"+Add-Me"
:
{
"Add-Value"
},
"-Remove-Me"
:
{
""
},
"Replace-Me"
:
{
"{hostname}"
},
"Host"
:
{
"{>Host}"
},
}
// set up proxy
p
:=
&
Proxy
{
...
...
@@ -385,10 +388,12 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
}
w
:=
httptest
.
NewRecorder
()
const
expectHost
=
"example.com"
//add initial headers
r
.
Header
.
Add
(
"Merge-Me"
,
"Initial"
)
r
.
Header
.
Add
(
"Remove-Me"
,
"Remove-Value"
)
r
.
Header
.
Add
(
"Replace-Me"
,
"Replace-Value"
)
r
.
Header
.
Add
(
"Host"
,
expectHost
)
p
.
ServeHTTP
(
w
,
r
)
...
...
@@ -421,6 +426,10 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
t
.
Errorf
(
"Request sent to upstream backend should replace value of %v header with %v. Instead value was %v"
,
headerKey
,
headerValue
,
value
)
}
if
actualHost
!=
expectHost
{
t
.
Errorf
(
"Request sent to upstream backend should have value of Host with %s, but got %s"
,
expectHost
,
actualHost
)
}
}
func
TestDownstreamHeadersUpdate
(
t
*
testing
.
T
)
{
...
...
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