Commit 395a5c8d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add std.collect() which will collect multiple HTTP headers into

one single header.

Example usage:

	import std;

	sub vcl_recv {
		std.collect(req.http.foo);
	}
	sub vcl_fetch {
		std.collect(beresp.http.bar);
	}

Fixes: #866
parent ee9e8034
# $Id$
test "test vmod_std.collect()"
server s1 {
rxreq
expect req.url == "/1"
expect req.http.foo == "1, 2"
txresp -hdr "bar: a" -hdr "bar: b" -bodylen 1
} -start
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
sub vcl_recv {
std.collect(req.http.foo);
}
sub vcl_fetch {
std.collect(beresp.http.bar);
}
} -start
client c1 {
txreq -url "/1" -hdr "Foo: 1" -hdr "Foo: 2"
rxresp
expect resp.http.bar == "a, b"
expect resp.status == 200
expect resp.bodylen == 1
} -run
varnish v1 -badvcl {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
std.collect(beresp.http.bar);
}
}
......@@ -36,3 +36,4 @@ Function VOID syslog(INT, STRING_LIST)
Function STRING fileread(PRIV_CALL, STRING)
Function STRING author(ENUM { phk, des, kristian, mithrandir })
Function DURATION duration(STRING, DURATION)
Function VOID collect(HEADER)
......@@ -176,3 +176,16 @@ vmod_author(struct sess *sp, const char *id)
return ("Tollef");
WRONG("Illegal VMOD enum");
}
void __match_proto__()
vmod_collect(struct sess *sp, enum gethdr_e e, const char *h)
{
(void)e;
(void)sp;
(void)h;
if (e == HDR_REQ)
http_CollectHdr(sp->http, h);
else if (e == HDR_BERESP)
http_CollectHdr(sp->wrk->beresp, h);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment