Commit b8ad16b1 authored by Geoff Simmons's avatar Geoff Simmons

set.string() and .backend() when no strings or backends were set.

parent a3a5bbf4
Pipeline #338 skipped
......@@ -11,6 +11,10 @@ varnish v1 -vcl {
s.add("foo", "baz");
s.add("bar", "quux");
s.compile();
new n = re2.set();
n.add("foo");
n.compile();
}
sub vcl_recv {
......@@ -38,6 +42,13 @@ varnish v1 -vcl {
set resp.http.s-many-first = s.string(select=FIRST);
set resp.http.s-many-last = s.string(select=LAST);
set resp.http.s-outofrange = s.string(3);
set resp.http.n-str-1 = n.string(1);
set resp.http.n-str-2 = n.string(2);
set resp.http.n-before-match = n.string();
set resp.http.n-foo-match = n.match("foo");
set resp.http.n-foo-n = n.nmatches();
set resp.http.n-foo-str = n.string();
}
} -start
......@@ -66,6 +77,12 @@ client c1 {
expect resp.http.s-many-first == "baz"
expect resp.http.s-many-last == "quux"
expect resp.http.s-outofrange == ""
expect resp.http.n-str-1 == ""
expect resp.http.n-str-2 == ""
expect resp.http.n-before-match == ""
expect resp.http.n-foo-match == "true"
expect resp.http.n-foo-n == 1
expect resp.http.n-foo-str == ""
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
......@@ -75,6 +92,10 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error "^vmod re2 error: s.string.0.: previous match was unsuccessful$"
expect * = VCL_Error "^vmod re2 error: s.string.0.: 2 successful matches$"
expect * = VCL_Error "^vmod re2 error: s.string.3.: set has 2 patterns$"
expect * = VCL_Error "^vmod re2 error: n.string.1.: No strings were set for n$"
expect * = VCL_Error "^vmod re2 error: n.string.2.: No strings were set for n$"
expect * = VCL_Error "^vmod re2 error: n.string.0.: No strings were set for n$"
expect * = VCL_Error "^vmod re2 error: n.string.0.: No strings were set for n$"
expect * = End
} -run
......@@ -89,6 +110,10 @@ varnish v1 -vcl {
b.add("foo", backend=b1);
b.add("bar", backend=b2);
b.compile();
new n = re2.set();
n.add("foo");
n.compile();
}
sub vcl_recv {
......@@ -116,6 +141,13 @@ varnish v1 -vcl {
set resp.http.b-many-first = b.backend(select=FIRST);
set resp.http.b-many-last = b.backend(select=LAST);
set resp.http.b-outofrange = b.backend(3);
set resp.http.n-backend-1 = n.backend(1);
set resp.http.n-backend-2 = n.backend(2);
set resp.http.n-before-match = n.backend();
set resp.http.n-foo-match = n.match("foo");
set resp.http.n-foo-n = n.nmatches();
set resp.http.n-foo-backend = n.backend();
}
}
......@@ -127,6 +159,10 @@ logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect * = VCL_Error "^vmod re2 error: b.backend.0.: previous match was unsuccessful$"
expect * = VCL_Error "^vmod re2 error: b.backend.0.: 2 successful matches$"
expect * = VCL_Error "^vmod re2 error: b.backend.3.: set has 2 patterns$"
expect * = VCL_Error "^vmod re2 error: n.backend.1.: No backends were set for n$"
expect * = VCL_Error "^vmod re2 error: n.backend.2.: No backends were set for n$"
expect * = VCL_Error "^vmod re2 error: n.backend.0.: No backends were set for n$"
expect * = VCL_Error "^vmod re2 error: n.backend.0.: No backends were set for n$"
expect * = End
} -start
......
......@@ -857,7 +857,17 @@ get_match_idx(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects,
VCL_STRING
vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
{
int idx = get_match_idx(ctx, set, n, selects, "string");
int idx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_RE2_SET_MAGIC);
if (set->string == NULL) {
VERR(ctx, "%s.string(%lld): No strings were set for %s",
set->vcl_name, n, set->vcl_name);
return NULL;
}
idx = get_match_idx(ctx, set, n, selects, "string");
if (idx < 0)
return NULL;
return set->string[idx];
......@@ -866,7 +876,17 @@ vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
VCL_BACKEND
vmod_set_backend(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
{
int idx = get_match_idx(ctx, set, n, selects, "backend");
int idx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_RE2_SET_MAGIC);
if (set->backend == NULL) {
VERR(ctx, "%s.backend(%lld): No backends were set for %s",
set->vcl_name, n, set->vcl_name);
return NULL;
}
idx = get_match_idx(ctx, set, n, selects, "backend");
if (idx < 0)
return NULL;
return set->backend[idx];
......
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