From e85ba0d4dbd5a0ecd6d47e08ce2023e5d533669b Mon Sep 17 00:00:00 2001 From: Tw Date: Thu, 3 Nov 2016 22:50:51 +0000 Subject: [PATCH] proxy: make value is optional when removing a header fix issue #1234 Signed-off-by: Tw --- caddyhttp/proxy/setup_test.go | 16 ++++++++++++++++ caddyhttp/proxy/upstream.go | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/caddyhttp/proxy/setup_test.go b/caddyhttp/proxy/setup_test.go index 7dff3bbc..02809058 100644 --- a/caddyhttp/proxy/setup_test.go +++ b/caddyhttp/proxy/setup_test.go @@ -131,6 +131,22 @@ func TestSetup(t *testing.T) { "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) err := setup(c) diff --git a/caddyhttp/proxy/upstream.go b/caddyhttp/proxy/upstream.go index dba4af3c..78ed4116 100644 --- a/caddyhttp/proxy/upstream.go +++ b/caddyhttp/proxy/upstream.go @@ -305,13 +305,19 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error { case "header_upstream": var header, value string 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) case "header_downstream": var header, value string 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) case "transparent":