Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-re
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-re
Commits
78bdc8b7
Commit
78bdc8b7
authored
Nov 23, 2014
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add the failed() method
parent
fb4b67ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
1 deletion
+157
-1
b01.vtc
src/tests/b01.vtc
+10
-0
b05.vtc
src/tests/b05.vtc
+13
-0
c08.vtc
src/tests/c08.vtc
+117
-0
vmod_re.c
src/vmod_re.c
+8
-0
vmod_re.vcc
src/vmod_re.vcc
+9
-1
No files found.
src/tests/b01.vtc
View file @
78bdc8b7
...
@@ -15,6 +15,16 @@ varnish v1 -vcl+backend {
...
@@ -15,6 +15,16 @@ varnish v1 -vcl+backend {
}
}
sub vcl_recv {
sub vcl_recv {
if (foobar.failed()) {
return(synth(999, "foobar failed"));
}
if (snafu.failed()) {
return(synth(999, "snafu failed"));
}
if (bar.failed()) {
return(synth(999, "bar failed"));
}
if (foobar.match(req.url)) {
if (foobar.match(req.url)) {
return(pass);
return(pass);
} else if (snafu.match(req.url)) {
} else if (snafu.match(req.url)) {
...
...
src/tests/b05.vtc
View file @
78bdc8b7
...
@@ -12,6 +12,12 @@ varnish v1 -vcl+backend {
...
@@ -12,6 +12,12 @@ varnish v1 -vcl+backend {
new paren = re.regex("(");
new paren = re.regex("(");
}
}
sub vcl_recv {
if (!paren.failed()) {
return(synth(999, "paren should have failed"));
}
}
sub vcl_backend_response {
sub vcl_backend_response {
if (paren.match(beresp.http.foo)) {
if (paren.match(beresp.http.foo)) {
set beresp.http.foo = "baz";
set beresp.http.foo = "baz";
...
@@ -22,7 +28,14 @@ varnish v1 -vcl+backend {
...
@@ -22,7 +28,14 @@ varnish v1 -vcl+backend {
client c1 {
client c1 {
txreq
txreq
rxresp
rxresp
expect resp.status == 200
expect resp.http.content-length == 6
expect resp.http.content-length == 6
expect resp.http.foo == "bar"
expect resp.http.foo == "bar"
expect resp.http.baz == "quux"
expect resp.http.baz == "quux"
} -run
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "vmod re: error compiling regex:"
expect * = End
} -run
src/tests/c08.vtc
0 → 100644
View file @
78bdc8b7
varnishtest "backrefs always fail when compilation failed"
server s1 {
rxreq
txresp -hdr "Foo: bar" -body "1111\n"
} -start
varnish v1 -vcl+backend {
import re from "${vmod_topbuild}/src/.libs/libvmod_re.so";
sub vcl_init {
new paren = re.regex("(");
new parend = re.regex("");
}
sub vcl_deliver {
set resp.http.paren = paren.failed();
/* match fails */
if (paren.match(resp.http.foo)) {
set resp.http.match = "success";
}
/* ... so all backrefs fail */
set resp.http.paren0 = paren.backref(0, "fallback0");
set resp.http.paren1 = paren.backref(1, "fallback1");
set resp.http.paren2 = paren.backref(2, "fallback2");
set resp.http.paren3 = paren.backref(3, "fallback3");
set resp.http.paren4 = paren.backref(4, "fallback4");
set resp.http.paren5 = paren.backref(5, "fallback5");
set resp.http.paren6 = paren.backref(6, "fallback6");
set resp.http.paren7 = paren.backref(7, "fallback7");
set resp.http.paren8 = paren.backref(8, "fallback8");
set resp.http.paren9 = paren.backref(9, "fallback9");
set resp.http.paren10 = paren.backref(10, "fallback10");
if (paren.match_dyn("(bar)", resp.http.foo)) {
# dynamic matches do not affect failed()
set resp.http.parend = paren.failed();
}
/* compilation fails */
if (parend.match_dyn(")", resp.http.foo)) {
set resp.http.matchd = "success";
}
/* ... so all backrefs fail */
set resp.http.paren0d = parend.backref(0, "fallback0");
set resp.http.paren1d = parend.backref(1, "fallback1");
set resp.http.paren2d = parend.backref(2, "fallback2");
set resp.http.paren3d = parend.backref(3, "fallback3");
set resp.http.paren4d = parend.backref(4, "fallback4");
set resp.http.paren5d = parend.backref(5, "fallback5");
set resp.http.paren6d = parend.backref(6, "fallback6");
set resp.http.paren7d = parend.backref(7, "fallback7");
set resp.http.paren8d = parend.backref(8, "fallback8");
set resp.http.paren9d = parend.backref(9, "fallback9");
set resp.http.paren10d = parend.backref(10, "fallback10");
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.paren == "true"
expect resp.http.match == <undef>
expect resp.http.paren0 == "fallback0"
expect resp.http.paren1 == "fallback1"
expect resp.http.paren2 == "fallback2"
expect resp.http.paren3 == "fallback3"
expect resp.http.paren4 == "fallback4"
expect resp.http.paren5 == "fallback5"
expect resp.http.paren6 == "fallback6"
expect resp.http.paren7 == "fallback7"
expect resp.http.paren8 == "fallback8"
expect resp.http.paren9 == "fallback9"
expect resp.http.paren10 == "fallback10"
expect resp.http.parend == "true"
expect resp.http.matchd == <undef>
expect resp.http.paren0d == "fallback0"
expect resp.http.paren1d == "fallback1"
expect resp.http.paren2d == "fallback2"
expect resp.http.paren3d == "fallback3"
expect resp.http.paren4d == "fallback4"
expect resp.http.paren5d == "fallback5"
expect resp.http.paren6d == "fallback6"
expect resp.http.paren7d == "fallback7"
expect resp.http.paren8d == "fallback8"
expect resp.http.paren9d == "fallback9"
expect resp.http.paren10d == "fallback10"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
# from match()
expect * = VCL_Error "^vmod re: error compiling regex:"
# from match_dyn()
expect * = VCL_Error "^vmod re: error compiling regex"
# from the backref() calls after match_dyn()
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = VCL_Error "^vmod re: backref called without prior match$"
expect * = End
} -run
src/vmod_re.c
View file @
78bdc8b7
...
@@ -107,6 +107,14 @@ vmod_regex__init(const struct vrt_ctx *ctx, struct vmod_re_regex **rep,
...
@@ -107,6 +107,14 @@ vmod_regex__init(const struct vrt_ctx *ctx, struct vmod_re_regex **rep,
#endif
#endif
}
}
VCL_BOOL
vmod_regex_failed
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_re_regex
*
re
)
{
(
void
)
ctx
;
CHECK_OBJ_NOTNULL
(
re
,
VMOD_RE_REGEX_MAGIC
);
return
(
re
->
error
!=
NULL
);
}
VCL_VOID
VCL_VOID
vmod_regex__fini
(
struct
vmod_re_regex
**
rep
)
vmod_regex__fini
(
struct
vmod_re_regex
**
rep
)
{
{
...
...
src/vmod_re.vcc
View file @
78bdc8b7
...
@@ -115,7 +115,15 @@ Description
...
@@ -115,7 +115,15 @@ Description
for extracting backreferences.
for extracting backreferences.
Example
Example
new myregex = re.regex("\bmax-age\s*=\s*(\d+)");
``new myregex = re.regex("\bmax-age\s*=\s*(\d+)");``
$Method BOOL .failed()
Description
Returns true if regex compilation in the constructor failed.
Example
``if (myregex.failed()) { # ...``
$Method BOOL .match(STRING)
$Method BOOL .match(STRING)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment