Commit 2b132048 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vmod: Teach VMODs to use REGEX expressions

When they take a regular expression as an argument, they can benefit
from compile time checks and avoid PRIV_CALL or on-the-fly regex
compilation.
parent 5391143e
varnishtest "REGEX expressions in VCL"
varnish v1 -vcl {
import debug;
backend be none;
sub vcl_recv {
# NB: the REGEX expression below is needlessly complicated
# on purpose to ensure we don't treat REGEX expressions
# differently.
if (req.url ~ (debug.just_return_regex(
debug.just_return_regex("hello")))) {
return (synth(200));
}
return (synth(500));
}
sub vcl_synth {
set resp.reason = regsub(resp.reason,
debug.just_return_regex("OK"), "world");
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 500
expect resp.reason == "Internal Server Error"
txreq -url "/hello"
rxresp
expect resp.status == 200
expect resp.reason == world
} -run
......@@ -381,6 +381,11 @@ REAL
A floating point value.
REGEX
C-type: ``const struct vre *``
This is an opaque type for regular expressions with a VCL scope.
STRING
C-type: ``const char *``
......
......@@ -110,6 +110,7 @@ CTYPES = {
'IP': "VCL_IP",
'PROBE': "VCL_PROBE",
'REAL': "VCL_REAL",
'REGEX': "VCL_REGEX",
'STEVEDORE': "VCL_STEVEDORE",
'STRANDS': "VCL_STRANDS",
'STRING': "VCL_STRING",
......
......@@ -1278,3 +1278,12 @@ xyzzy_validhdr(VRT_CTX, VCL_STRANDS s)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
return (VRT_ValidHdr(ctx, s));
}
VCL_REGEX v_matchproto_(td_xyzzy_regex)
xyzzy_just_return_regex(VRT_CTX, VCL_REGEX r)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(r);
return (r);
}
......@@ -319,3 +319,7 @@ A function mixing a named PRIV_TASK with optional parameters.
$Function BOOL validhdr(STRANDS)
Test if the argument is a valid header according to RFC7230 section 3.2.
$Function REGEX just_return_regex(REGEX)
Take a REGEX argument and return it.
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