c03.vtc 3.33 KB
Newer Older
Geoff Simmons's avatar
Geoff Simmons committed
1 2 3
varnishtest "backref failure with dynamic matches"

# same as c02.vtc, but with match_dyn()
Geoff Simmons's avatar
Geoff Simmons committed
4 5 6

server s1 {
	rxreq
Geoff Simmons's avatar
Geoff Simmons committed
7 8
	txresp -hdr "Foo: barbaz" -hdr "Bar: bazquux" -hdr "Barf: barf" \
	       -body "1111\n"
Geoff Simmons's avatar
Geoff Simmons committed
9 10 11 12 13
} -start

varnish v1 -vcl+backend {
	import re from "${vmod_topbuild}/src/.libs/libvmod_re.so";

Geoff Simmons's avatar
Geoff Simmons committed
14
	sub vcl_deliver {
15
		set resp.http.nomatch = re.backref_dyn(0, "fallback");
Geoff Simmons's avatar
Geoff Simmons committed
16

17
		if (re.match_dyn("(frob)(nitz)", resp.http.foo)) {
Geoff Simmons's avatar
Geoff Simmons committed
18 19
			set resp.http.frob = "nitz";
		}
20 21 22 23 24 25 26 27 28 29 30
		set resp.http.frob0 = re.backref_dyn(0, "fallback0");
		set resp.http.frob1 = re.backref_dyn(1, "fallback1");
		set resp.http.frob2 = re.backref_dyn(2, "fallback2");
		set resp.http.frob3 = re.backref_dyn(3, "fallback3");
		set resp.http.frob4 = re.backref_dyn(4, "fallback4");
		set resp.http.frob5 = re.backref_dyn(5, "fallback5");
		set resp.http.frob6 = re.backref_dyn(6, "fallback6");
		set resp.http.frob7 = re.backref_dyn(7, "fallback7");
		set resp.http.frob8 = re.backref_dyn(8, "fallback8");
		set resp.http.frob9 = re.backref_dyn(9, "fallback9");
		set resp.http.frob10 = re.backref_dyn(10, "fallback10");
Geoff Simmons's avatar
Geoff Simmons committed
31

32 33 34 35 36
		if (re.match_dyn("(bar)(baz)", resp.http.foo)) {
			set resp.http.foo0 = re.backref_dyn(0, "error0");
			set resp.http.foo1 = re.backref_dyn(1, "error1");
			set resp.http.foo2 = re.backref_dyn(2, "error2");
			set resp.http.foo3 = re.backref_dyn(3, "foofallback");
Geoff Simmons's avatar
Geoff Simmons committed
37
		}
38
		if (re.match_dyn("(bar)(baz)", resp.http.barf)) {
Geoff Simmons's avatar
Geoff Simmons committed
39 40
			set resp.http.puke = "match";
		}
41 42 43 44 45 46 47 48 49 50 51
		set resp.http.barf0 = re.backref_dyn(0, "fallback0");
		set resp.http.barf1 = re.backref_dyn(1, "fallback1");
		set resp.http.barf2 = re.backref_dyn(2, "fallback2");
		set resp.http.barf3 = re.backref_dyn(3, "fallback3");
		set resp.http.barf4 = re.backref_dyn(4, "fallback4");
		set resp.http.barf5 = re.backref_dyn(5, "fallback5");
		set resp.http.barf6 = re.backref_dyn(6, "fallback6");
		set resp.http.barf7 = re.backref_dyn(7, "fallback7");
		set resp.http.barf8 = re.backref_dyn(8, "fallback8");
		set resp.http.barf9 = re.backref_dyn(9, "fallback9");
		set resp.http.barf10 = re.backref_dyn(10, "fallback10");
Geoff Simmons's avatar
Geoff Simmons committed
52 53 54 55 56 57 58
	}

} -start

client c1 {
	txreq
	rxresp
Geoff Simmons's avatar
Geoff Simmons committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72
	expect resp.status == 200
	expect resp.http.nomatch == "fallback"
	expect resp.http.frob == <undef>
	expect resp.http.frob0 == "fallback0"
	expect resp.http.frob1 == "fallback1"
	expect resp.http.frob2 == "fallback2"
	expect resp.http.frob3 == "fallback3"
	expect resp.http.frob4 == "fallback4"
	expect resp.http.frob5 == "fallback5"
	expect resp.http.frob6 == "fallback6"
	expect resp.http.frob7 == "fallback7"
	expect resp.http.frob8 == "fallback8"
	expect resp.http.frob9 == "fallback9"
	expect resp.http.frob10 == "fallback10"
73
	expect resp.http.foo0 == "barbaz"
Geoff Simmons's avatar
Geoff Simmons committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	expect resp.http.foo1 == "bar"
	expect resp.http.foo2 == "baz"
	expect resp.http.foo3 == "foofallback"
	expect resp.http.puke == <undef>
	expect resp.http.barf0 == "fallback0"
	expect resp.http.barf1 == "fallback1"
	expect resp.http.barf2 == "fallback2"
	expect resp.http.barf3 == "fallback3"
	expect resp.http.barf4 == "fallback4"
	expect resp.http.barf5 == "fallback5"
	expect resp.http.barf6 == "fallback6"
	expect resp.http.barf7 == "fallback7"
	expect resp.http.barf8 == "fallback8"
	expect resp.http.barf9 == "fallback9"
	expect resp.http.barf10 == "fallback10"
} -run

logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
	expect 0 * Begin req
	expect * = VCL_Error "vmod re: backref called without prior match"
	expect * = End
Geoff Simmons's avatar
Geoff Simmons committed
95
} -run