varnishtest "Test header filtering Table/Connection header"

server s1 {
	rxreq
	expect req.url == "/foo"
	expect req.http.Foo == "bar"
	expect req.http.FromVCL == "123"
	expect req.http.Proxy-Authenticate == "<undef>"
	expect req.http.pROXY-aUTHENTICATE == "<undef>"
	expect req.http.Proxy-Authenticat == "3"
	expect req.http.Proxy-Authenticatd == "4"
	expect req.http.Proxy-Authenticatef == "5"
	txresp -hdr "Bar: foo" -body "foobar"

	rxreq
	expect req.url == "/bar"
	expect req.http.Foo == <undef>
	expect req.http.FromVCL == "123"
	txresp	-hdr "Bar: fnry,glyf, FOO ,brok" \
		-hdr "Connection: bar" \
		-body "foobar"
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		set req.http.FromVCL = "123";
	}
} -start

client c1 {
	txreq -url "/foo" -hdr "Foo: bar" \
		-hdr "Proxy-Authenticate: 1" \
		-hdr "pROXY-aUTHENTICATE: 2" \
		-hdr "Proxy-Authenticat: 3" \
		-hdr "Proxy-Authenticatd: 4" \
		-hdr "Proxy-Authenticatef: 5"

	rxresp
	expect resp.http.Bar == "foo"

	txreq	-url "/bar" \
		-hdr "Foo: bar2" \
		-hdr "Connection: FromVCL, foo, close"
	rxresp
	expect req.http.Bar == <undef>
} -run

client c1 {
	txreq	-url "/bar" \
		-hdr "foo: 1" \
		-hdr "Age: 200" \
		-hdr "Connection: Age"
	rxresp
	expect resp.status == 400
} -run

server s1 {
	rxreq
	expect req.http.baa == ""
	expect req.http.baax == <undef>
	txresp -hdr "Foox: 1" -hdr "foox: 2" -hdr "Connection: foox"
}  -start

varnish v1 -vcl+backend {
	sub vcl_backend_fetch {
		set bereq.http.baa = bereq.http.baax;
	}
	sub vcl_deliver {
		set resp.http.foo = resp.http.foox;
	}
}

client c1 {
	txreq -hdr "Baax: 1" -hdr "Baax: 2" -hdr "Connection: baax"
	rxresp
	expect resp.status == 200
	expect resp.http.foo == ""
	expect resp.http.foox == <undef>
} -run
