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
7497cb26
Commit
7497cb26
authored
Apr 28, 2018
by
comp500
Committed by
Łukasz Nowak
Nov 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests, fix a few bugs
parent
b2e0264f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
16 deletions
+40
-16
caddyhttp/proxy/proxy.go
caddyhttp/proxy/proxy.go
+1
-1
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+36
-12
caddyhttp/proxy/upstream.go
caddyhttp/proxy/upstream.go
+3
-3
No files found.
caddyhttp/proxy/proxy.go
View file @
7497cb26
...
@@ -232,7 +232,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
...
@@ -232,7 +232,7 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// headers coming back downstream
// headers coming back downstream
var
downHeaderUpdateFn
respUpdateFn
var
downHeaderUpdateFn
respUpdateFn
if
host
.
DownstreamHeaders
!=
nil
{
if
host
.
DownstreamHeaders
!=
nil
{
downHeaderUpdateFn
=
createRespHeaderUpdateFn
(
host
.
DownstreamHeaders
,
replacer
,
host
.
Up
streamHeaderReplacements
)
downHeaderUpdateFn
=
createRespHeaderUpdateFn
(
host
.
DownstreamHeaders
,
replacer
,
host
.
Down
streamHeaderReplacements
)
}
}
// Before we retry the request we have to make sure
// Before we retry the request we have to make sure
...
...
caddyhttp/proxy/proxy_test.go
View file @
7497cb26
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"path"
"path"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"regexp"
"runtime"
"runtime"
"strings"
"strings"
"sync"
"sync"
...
@@ -724,6 +725,14 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
...
@@ -724,6 +725,14 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
"Clear-Me"
:
{
""
},
"Clear-Me"
:
{
""
},
"Host"
:
{
"{>Host}"
},
"Host"
:
{
"{>Host}"
},
}
}
regex1
,
_
:=
regexp
.
Compile
(
"was originally"
)
regex2
,
_
:=
regexp
.
Compile
(
"this"
)
regex3
,
_
:=
regexp
.
Compile
(
"bad"
)
upstream
.
host
.
UpstreamHeaderReplacements
=
headerReplacements
{
"Regex-Me"
:
{
headerReplacement
{
regex1
,
"am now"
},
headerReplacement
{
regex2
,
"that"
}},
"Regexreplace-Me"
:
{
headerReplacement
{
regex3
,
"{hostname}"
}},
}
// set up proxy
// set up proxy
p
:=
&
Proxy
{
p
:=
&
Proxy
{
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
...
@@ -740,6 +749,8 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
...
@@ -740,6 +749,8 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
r
.
Header
.
Add
(
"Remove-Me"
,
"Remove-Value"
)
r
.
Header
.
Add
(
"Remove-Me"
,
"Remove-Value"
)
r
.
Header
.
Add
(
"Replace-Me"
,
"Replace-Value"
)
r
.
Header
.
Add
(
"Replace-Me"
,
"Replace-Value"
)
r
.
Header
.
Add
(
"Host"
,
expectHost
)
r
.
Header
.
Add
(
"Host"
,
expectHost
)
r
.
Header
.
Add
(
"Regex-Me"
,
"I was originally this"
)
r
.
Header
.
Add
(
"Regexreplace-Me"
,
"The host is bad"
)
p
.
ServeHTTP
(
w
,
r
)
p
.
ServeHTTP
(
w
,
r
)
...
@@ -752,6 +763,8 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
...
@@ -752,6 +763,8 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
"Remove-Me"
:
nil
,
"Remove-Me"
:
nil
,
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Clear-Me"
:
nil
,
"Clear-Me"
:
nil
,
"Regex-Me"
:
{
"I am now that"
},
"Regexreplace-Me"
:
{
"The host is "
+
replacer
.
Replace
(
"{hostname}"
)},
}
{
}
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Upstream request does not contain expected %v header: expect %v, but got %v"
,
t
.
Errorf
(
"Upstream request does not contain expected %v header: expect %v, but got %v"
,
...
@@ -775,6 +788,8 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
...
@@ -775,6 +788,8 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
w
.
Header
()
.
Add
(
"Replace-Me"
,
"Replace-Value"
)
w
.
Header
()
.
Add
(
"Replace-Me"
,
"Replace-Value"
)
w
.
Header
()
.
Add
(
"Content-Type"
,
"text/html"
)
w
.
Header
()
.
Add
(
"Content-Type"
,
"text/html"
)
w
.
Header
()
.
Add
(
"Overwrite-Me"
,
"Overwrite-Value"
)
w
.
Header
()
.
Add
(
"Overwrite-Me"
,
"Overwrite-Value"
)
w
.
Header
()
.
Add
(
"Regex-Me"
,
"I was originally this"
)
w
.
Header
()
.
Add
(
"Regexreplace-Me"
,
"The host is bad"
)
w
.
Write
([]
byte
(
"Hello, client"
))
w
.
Write
([]
byte
(
"Hello, client"
))
}))
}))
defer
backend
.
Close
()
defer
backend
.
Close
()
...
@@ -786,6 +801,13 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
...
@@ -786,6 +801,13 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
"-Remove-Me"
:
{
""
},
"-Remove-Me"
:
{
""
},
"Replace-Me"
:
{
"{hostname}"
},
"Replace-Me"
:
{
"{hostname}"
},
}
}
regex1
,
_
:=
regexp
.
Compile
(
"was originally"
)
regex2
,
_
:=
regexp
.
Compile
(
"this"
)
regex3
,
_
:=
regexp
.
Compile
(
"bad"
)
upstream
.
host
.
DownstreamHeaderReplacements
=
headerReplacements
{
"Regex-Me"
:
{
headerReplacement
{
regex1
,
"am now"
},
headerReplacement
{
regex2
,
"that"
}},
"Regexreplace-Me"
:
{
headerReplacement
{
regex3
,
"{hostname}"
}},
}
// set up proxy
// set up proxy
p
:=
&
Proxy
{
p
:=
&
Proxy
{
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
Next
:
httpserver
.
EmptyNext
,
// prevents panic in some cases when test fails
...
@@ -812,6 +834,8 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
...
@@ -812,6 +834,8 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Content-Type"
:
{
"text/css"
},
"Content-Type"
:
{
"text/css"
},
"Overwrite-Me"
:
{
"Overwrite-Value"
},
"Overwrite-Me"
:
{
"Overwrite-Value"
},
"Regex-Me"
:
{
"I am now that"
},
"Regexreplace-Me"
:
{
"The host is "
+
replacer
.
Replace
(
"{hostname}"
)},
}
{
}
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
...
...
caddyhttp/proxy/upstream.go
View file @
7497cb26
...
@@ -461,7 +461,7 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream, hasSrv bool) error {
...
@@ -461,7 +461,7 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream, hasSrv bool) error {
}
}
u
.
upstreamHeaderReplacements
.
Add
(
header
,
headerReplacement
{
r
,
replaced
})
u
.
upstreamHeaderReplacements
.
Add
(
header
,
headerReplacement
{
r
,
replaced
})
}
else
{
}
else
{
if
!
c
.
Args
(
&
header
,
&
value
)
{
if
len
(
value
)
==
0
{
// When removing a header, the value can be optional.
// When removing a header, the value can be optional.
if
!
strings
.
HasPrefix
(
header
,
"-"
)
{
if
!
strings
.
HasPrefix
(
header
,
"-"
)
{
return
c
.
ArgErr
()
return
c
.
ArgErr
()
...
@@ -480,9 +480,9 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream, hasSrv bool) error {
...
@@ -480,9 +480,9 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream, hasSrv bool) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
c
.
ArgErr
()
return
c
.
ArgErr
()
}
}
u
.
up
streamHeaderReplacements
.
Add
(
header
,
headerReplacement
{
r
,
replaced
})
u
.
down
streamHeaderReplacements
.
Add
(
header
,
headerReplacement
{
r
,
replaced
})
}
else
{
}
else
{
if
!
c
.
Args
(
&
header
,
&
value
)
{
if
len
(
value
)
==
0
{
// When removing a header, the value can be optional.
// When removing a header, the value can be optional.
if
!
strings
.
HasPrefix
(
header
,
"-"
)
{
if
!
strings
.
HasPrefix
(
header
,
"-"
)
{
return
c
.
ArgErr
()
return
c
.
ArgErr
()
...
...
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