Commit b0c3bd67 authored by Geoff Simmons's avatar Geoff Simmons

Add the element enum to .string().

parent aef01728
......@@ -753,13 +753,14 @@ Example::
.. _xset.string():
STRING xset.string(INT n, ENUM select)
--------------------------------------
STRING xset.string(INT n, STRING element, ENUM select)
------------------------------------------------------
::
STRING xset.string(
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
......
......@@ -43,6 +43,17 @@ varnish v1 -vcl {
set resp.http.String-Longest
= s.string(select=LONGEST);
}
set resp.http.Foo = s.string(element="foo");
set resp.http.Bar = s.string(element="bar");
set resp.http.Baz = s.string(element="baz");
set resp.http.Quux = s.string(element="quux");
set resp.http.Foobar = s.string(element="foobar");
if (req.http.Element) {
set resp.http.Element
= s.string(element=req.http.Element);
}
return (deliver);
}
} -start
......@@ -57,6 +68,12 @@ client c1 {
expect resp.http.N-4 == "xuuq"
expect resp.http.N-5 == "raboof"
expect resp.http.Foo == "oof"
expect resp.http.Bar == "rab"
expect resp.http.Baz == "zab"
expect resp.http.Quux == "xuuq"
expect resp.http.Foobar == "raboof"
txreq -hdr "Word: foo"
rxresp
expect resp.status == 200
......@@ -128,6 +145,11 @@ client c1 {
expect_close
} -run
client c1 {
txreq -hdr "Element: oof"
expect_close
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.string\(\) called without prior match$}
......@@ -143,6 +165,11 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^vmod selector failure: s\.string\(6\): set has 5 elements$}
expect * = VCL_return fail
expect * = End
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.string\(element="oof"\): no such element$}
expect * = VCL_return fail
expect * = End
} -run
varnish v1 -vcl {
......@@ -187,6 +214,18 @@ varnish v1 -vcl {
set resp.http.String-Longest
= s.string(select=LONGEST);
}
if (req.http.Element) {
set resp.http.Element
= s.string(element=req.http.Element);
set resp.http.Element-Unique = s.string(select=UNIQUE);
set resp.http.Element-Exact = s.string(select=EXACT);
set resp.http.Element-First = s.string(select=FIRST);
set resp.http.Element-Last = s.string(select=LAST);
set resp.http.Element-Shortest
= s.string(select=SHORTEST);
set resp.http.Element-Longest
= s.string(select=LONGEST);
}
return (deliver);
}
}
......@@ -246,6 +285,17 @@ client c1 {
expect resp.http.String-Last == "4"
expect resp.http.String-Shortest == "4"
expect resp.http.String-Longest == "3"
txreq -hdr "Element: foo"
rxresp
expect resp.status == 200
expect resp.http.Element == "4"
expect resp.http.Element-Unique == "4"
expect resp.http.Element-Exact == "4"
expect resp.http.Element-First == "4"
expect resp.http.Element-Last == "4"
expect resp.http.Element-Shortest == "4"
expect resp.http.Element-Longest == "4"
} -run
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
......
......@@ -774,7 +774,7 @@ vmod_set_backend(VRT_CTX, struct vmod_selector_set *set, VCL_INT n,
VCL_STRING
vmod_set_string(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
VCL_ENUM selects)
VCL_STRING element, VCL_ENUM selects)
{
unsigned idx;
VCL_STRING s;
......@@ -782,7 +782,7 @@ vmod_set_string(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
idx = get_idx(ctx, n, set, "string", NULL, selects);
idx = get_idx(ctx, n, set, "string", element, selects);
if (idx == UINT_MAX)
return (NULL);
if (!check_added(ctx, set, idx, STRING, "string", "string"))
......
......@@ -677,7 +677,7 @@ Example::
set bereq.backend = myset.backend(select=LONGEST);
}
$Method STRING .string(INT n=0,
$Method STRING .string(INT n=0, STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
......
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