mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-07 19:38:49 +03:00
proxy: make value is optional when removing a header
fix issue #1234 Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
parent
b89cbe18e2
commit
e85ba0d4db
2 changed files with 24 additions and 2 deletions
|
@ -131,6 +131,22 @@ func TestSetup(t *testing.T) {
|
||||||
"http://localhost:8005/a--b": {},
|
"http://localhost:8005/a--b": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// test #12 test value is optional when remove upstream header
|
||||||
|
{
|
||||||
|
"proxy / localhost:1984 {\n header_upstream -server \n}",
|
||||||
|
false,
|
||||||
|
map[string]struct{}{
|
||||||
|
"http://localhost:1984": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// test #13 test value is optional when remove downstream header
|
||||||
|
{
|
||||||
|
"proxy / localhost:1984 {\n header_downstream -server \n}",
|
||||||
|
false,
|
||||||
|
map[string]struct{}{
|
||||||
|
"http://localhost:1984": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
c := caddy.NewTestController("http", test.input)
|
c := caddy.NewTestController("http", test.input)
|
||||||
err := setup(c)
|
err := setup(c)
|
||||||
|
|
|
@ -305,13 +305,19 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error {
|
||||||
case "header_upstream":
|
case "header_upstream":
|
||||||
var header, value string
|
var header, value string
|
||||||
if !c.Args(&header, &value) {
|
if !c.Args(&header, &value) {
|
||||||
return c.ArgErr()
|
// When removing a header, the value can be optional.
|
||||||
|
if !strings.HasPrefix(header, "-") {
|
||||||
|
return c.ArgErr()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u.upstreamHeaders.Add(header, value)
|
u.upstreamHeaders.Add(header, value)
|
||||||
case "header_downstream":
|
case "header_downstream":
|
||||||
var header, value string
|
var header, value string
|
||||||
if !c.Args(&header, &value) {
|
if !c.Args(&header, &value) {
|
||||||
return c.ArgErr()
|
// When removing a header, the value can be optional.
|
||||||
|
if !strings.HasPrefix(header, "-") {
|
||||||
|
return c.ArgErr()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u.downstreamHeaders.Add(header, value)
|
u.downstreamHeaders.Add(header, value)
|
||||||
case "transparent":
|
case "transparent":
|
||||||
|
|
Loading…
Reference in a new issue