Commit 1f071898 authored by Geoff Simmons's avatar Geoff Simmons

Add the element enum to .re_match().

parent fabdb68e
......@@ -818,14 +818,15 @@ Example::
.. _xset.re_match():
BOOL xset.re_match(STRING subject, INT n, ENUM select)
------------------------------------------------------
BOOL xset.re_match(STRING subject, INT n, STRING element, ENUM select)
----------------------------------------------------------------------
::
BOOL xset.re_match(
STRING subject,
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
......
......@@ -62,6 +62,23 @@ varnish v1 -vcl {
set resp.http.Nonmatch-Longest
= s.re_match(req.http.Word, select=LONGEST);
}
if (req.http.Element) {
set resp.http.Element
= s.re_match(req.http.Subject,
element=req.http.Element);
set resp.http.Element-Unique
= s.re_match(req.http.Subject, select=UNIQUE);
set resp.http.Element-Exact
= s.re_match(req.http.Subject, select=EXACT);
set resp.http.Element-First
= s.re_match(req.http.Subject, select=FIRST);
set resp.http.Element-Last
= s.re_match(req.http.Subject, select=LAST);
set resp.http.Element-Shortest
= s.re_match(req.http.Subject, select=SHORTEST);
set resp.http.Element-Longest
= s.re_match(req.http.Subject, select=LONGEST);
}
return (deliver);
}
} -start
......@@ -197,6 +214,17 @@ client c1 {
expect resp.http.Nonmatch-Last == "false"
expect resp.http.Nonmatch-Shortest == "false"
expect resp.http.Nonmatch-Longest == "false"
txreq -hdr "Element: foo" -hdr "Subject: oof"
rxresp
expect resp.status == 200
expect resp.http.Element == "true"
expect resp.http.Element-Unique == resp.http.Element
expect resp.http.Element-Exact == resp.http.Element
expect resp.http.Element-First == "true"
expect resp.http.Element-Last == "true"
expect resp.http.Element-Shortest == "true"
expect resp.http.Element-Longest == "true"
} -run
client c1 {
......@@ -214,6 +242,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\.re_match\(\) called without prior match$}
......@@ -229,6 +262,11 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^vmod selector failure: s\.re_match\(6\): set has 5 elements$}
expect * = VCL_return fail
expect * = End
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.re_match\(element="oof"\): no such element$}
expect * = VCL_return fail
expect * = End
} -run
varnish v1 -vcl {
......
......@@ -813,7 +813,7 @@ vmod_set_integer(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
static vre_t *
get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
VCL_INT n, VCL_ENUM const restrict selects,
VCL_INT n, VCL_STRING element, VCL_ENUM const restrict selects,
const char * const restrict method)
{
unsigned idx;
......@@ -822,7 +822,7 @@ get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
idx = get_idx(ctx, n, set, method, NULL, selects);
idx = get_idx(ctx, n, set, method, element, selects);
if (idx == UINT_MAX)
return (NULL);
if (!check_added(ctx, set, idx, REGEX, method, "regex"))
......@@ -835,11 +835,11 @@ get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
VCL_BOOL
vmod_set_re_match(VRT_CTX, struct vmod_selector_set *set, VCL_STRING subject,
VCL_INT n, VCL_ENUM selects)
VCL_INT n, VCL_STRING element, VCL_ENUM selects)
{
vre_t *re;
re = get_re(ctx, set, n, selects, "re_match");
re = get_re(ctx, set, n, element, selects, "re_match");
if (re == NULL)
return (0);
return (VRT_re_match(ctx, subject, re));
......@@ -851,7 +851,7 @@ vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
{
vre_t *re;
re = get_re(ctx, set, n, selects, "sub");
re = get_re(ctx, set, n, NULL, selects, "sub");
if (re == NULL)
return (NULL);
return (VRT_regsub(ctx, all, str, re, sub));
......
......@@ -724,7 +724,7 @@ Example::
}
}
$Method BOOL .re_match(STRING subject, INT n=0,
$Method BOOL .re_match(STRING subject, 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