[master] 395a5c8 Add std.collect() which will collect multiple HTTP headers into one single header.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Mar 14 10:48:48 CET 2011
commit 395a5c8deee8cd9410964ccbfd9cce9843cbb3a2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Mar 14 09:47:16 2011 +0000
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
diff --git a/bin/varnishtest/tests/m00006.vtc b/bin/varnishtest/tests/m00006.vtc
new file mode 100644
index 0000000..cdec1f9
--- /dev/null
+++ b/bin/varnishtest/tests/m00006.vtc
@@ -0,0 +1,40 @@
+# $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);
+ }
+}
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index d77d49a..121b375 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -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)
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 4be07c7..5a132ac 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -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);
+}
+
More information about the varnish-commit
mailing list