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
d5c97607
Commit
d5c97607
authored
Nov 23, 2014
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add the error() method
parent
78bdc8b7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
3 deletions
+55
-3
b01.vtc
src/tests/b01.vtc
+8
-0
b05.vtc
src/tests/b05.vtc
+5
-0
c08.vtc
src/tests/c08.vtc
+7
-1
vmod_re.c
src/vmod_re.c
+19
-0
vmod_re.vcc
src/vmod_re.vcc
+16
-2
No files found.
src/tests/b01.vtc
View file @
d5c97607
...
@@ -46,6 +46,10 @@ varnish v1 -vcl+backend {
...
@@ -46,6 +46,10 @@ varnish v1 -vcl+backend {
} else {
} else {
set beresp.status = 999;
set beresp.status = 999;
}
}
set beresp.http.foobarerr = foobar.error();
set beresp.http.snafuerr = snafu.error();
set beresp.http.barerr = bar.error();
}
}
} -start
} -start
...
@@ -56,4 +60,8 @@ client c1 {
...
@@ -56,4 +60,8 @@ client c1 {
expect resp.status == "200"
expect resp.status == "200"
expect resp.http.foo1 == "1"
expect resp.http.foo1 == "1"
expect resp.http.bar1 == "2"
expect resp.http.bar1 == "2"
expect resp.http.foobarerr == ""
expect resp.http.snafuerr == ""
expect resp.http.barerr == ""
} -run
} -run
src/tests/b05.vtc
View file @
d5c97607
...
@@ -22,6 +22,9 @@ varnish v1 -vcl+backend {
...
@@ -22,6 +22,9 @@ varnish v1 -vcl+backend {
if (paren.match(beresp.http.foo)) {
if (paren.match(beresp.http.foo)) {
set beresp.http.foo = "baz";
set beresp.http.foo = "baz";
}
}
else {
set beresp.http.error = paren.error();
}
}
}
} -start
} -start
...
@@ -32,6 +35,8 @@ client c1 {
...
@@ -32,6 +35,8 @@ client c1 {
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"
expect resp.http.error != <undef>
expect resp.http.error != ""
} -run
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
...
...
src/tests/c08.vtc
View file @
d5c97607
...
@@ -15,6 +15,7 @@ varnish v1 -vcl+backend {
...
@@ -15,6 +15,7 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
sub vcl_deliver {
set resp.http.paren = paren.failed();
set resp.http.paren = paren.failed();
set resp.http.error = paren.error();
/* match fails */
/* match fails */
if (paren.match(resp.http.foo)) {
if (paren.match(resp.http.foo)) {
...
@@ -34,8 +35,9 @@ varnish v1 -vcl+backend {
...
@@ -34,8 +35,9 @@ varnish v1 -vcl+backend {
set resp.http.paren10 = paren.backref(10, "fallback10");
set resp.http.paren10 = paren.backref(10, "fallback10");
if (paren.match_dyn("(bar)", resp.http.foo)) {
if (paren.match_dyn("(bar)", resp.http.foo)) {
# dynamic matches do not affect failed()
# dynamic matches do not affect failed()
or error()
set resp.http.parend = paren.failed();
set resp.http.parend = paren.failed();
set resp.http.errord = paren.error();
}
}
/* compilation fails */
/* compilation fails */
...
@@ -63,6 +65,8 @@ client c1 {
...
@@ -63,6 +65,8 @@ client c1 {
rxresp
rxresp
expect resp.status == 200
expect resp.status == 200
expect resp.http.paren == "true"
expect resp.http.paren == "true"
expect resp.http.error != <undef>
expect resp.http.error != ""
expect resp.http.match == <undef>
expect resp.http.match == <undef>
expect resp.http.paren0 == "fallback0"
expect resp.http.paren0 == "fallback0"
expect resp.http.paren1 == "fallback1"
expect resp.http.paren1 == "fallback1"
...
@@ -78,6 +82,8 @@ client c1 {
...
@@ -78,6 +82,8 @@ client c1 {
expect resp.http.parend == "true"
expect resp.http.parend == "true"
expect resp.http.matchd == <undef>
expect resp.http.matchd == <undef>
expect resp.http.errord != <undef>
expect resp.http.errord != ""
expect resp.http.paren0d == "fallback0"
expect resp.http.paren0d == "fallback0"
expect resp.http.paren1d == "fallback1"
expect resp.http.paren1d == "fallback1"
expect resp.http.paren2d == "fallback2"
expect resp.http.paren2d == "fallback2"
...
...
src/vmod_re.c
View file @
d5c97607
...
@@ -115,6 +115,25 @@ vmod_regex_failed(const struct vrt_ctx *ctx, struct vmod_re_regex *re)
...
@@ -115,6 +115,25 @@ vmod_regex_failed(const struct vrt_ctx *ctx, struct vmod_re_regex *re)
return
(
re
->
error
!=
NULL
);
return
(
re
->
error
!=
NULL
);
}
}
VCL_STRING
vmod_regex_error
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_re_regex
*
re
)
{
VCL_STRING
error
;
CHECK_OBJ_NOTNULL
(
re
,
VMOD_RE_REGEX_MAGIC
);
if
(
re
->
error
==
NULL
)
return
""
;
error
=
(
VCL_STRING
)
WS_Printf
(
ctx
->
ws
,
"%s (position %d)"
,
re
->
error
,
re
->
erroffset
);
if
(
error
==
NULL
)
{
VSLb
(
ctx
->
vsl
,
SLT_VCL_Error
,
"vmod re: insufficient workspace for error message"
);
return
"insufficient workspace for error message"
;
}
return
(
error
);
}
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 @
d5c97607
...
@@ -121,10 +121,23 @@ $Method BOOL .failed()
...
@@ -121,10 +121,23 @@ $Method BOOL .failed()
Description
Description
Returns true if regex compilation in the constructor failed.
Returns true if regex compilation in the constructor failed.
NOTE: This method only pertains to compilation in the
constructor, not to compilation of a regex in ``match_dyn``.
Example
Example
``if (myregex.failed()) { # ...``
``if (myregex.failed()) { # ...``
$Method STRING .error()
Description
Returns an error message if regex compilation in the
constructor failed, or the empty string if compilation
succedded. Like ``failed`` this only pertains to failures of
compilation in the constructor, not in ``match_dyn``.
Example
``std.log("myregex failed to compile: " + myregex.error());``
$Method BOOL .match(STRING)
$Method BOOL .match(STRING)
Description
Description
...
@@ -262,8 +275,9 @@ LIMITATIONS
...
@@ -262,8 +275,9 @@ LIMITATIONS
Regular expressions passed into the constructor and into ``match_dyn``
Regular expressions passed into the constructor and into ``match_dyn``
are compiled at run-time, so there are no errors at VCL compile-time
are compiled at run-time, so there are no errors at VCL compile-time
for invalid expressions. If an expression is invalid, then a
for invalid expressions. If an expression is invalid, then a
``VCL_error`` message is emitted to the Varnish log, and matches
``VCL_error`` message is emitted to the Varnish log, matches always
always fail.
fail, and errors in the constructor can be inspected with ``failed``
and ``error``.
The VMOD allocates memory for captured subexpressions from Varnish
The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters
workspaces, whose sizes are determined by the runtime parameters
...
...
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