Commit 110aefdd authored by Geoff Simmons's avatar Geoff Simmons

Backport for Varnish 5.0.0.

parent c3797b83
......@@ -358,8 +358,7 @@ A regular expression in the ``regex`` parameter is compiled at VCL load
time. If the compile fails, then the VCL load fails with an error message.
Regular expressions are evaluated exactly as native regexen in VCL.
``.add()`` fails and invokes VCL failure (see `ERRORS`_) under the
following conditions:
``.add()`` fails under the following conditions:
* ``.add()`` is called any subroutine besides ``vcl_init``.
......@@ -369,6 +368,9 @@ following conditions:
* A regular expression in the ``regex`` parameter fails to compile.
See `ERRORS`_ below for details about error handling, for this and all
other methods.
Example::
sub vcl_init {
......@@ -759,33 +761,18 @@ Example::
ERRORS
======
The method documentation above refers to two kinds of failures: method
failure and VCL failure.
When a method fails, an error message is written to the Varnish log
with the ``VCL_Error`` tag, and the method returns an "error" value,
which depends on the return type, as documented above.
VCL failure has the same results as if ``return(fail)`` is called from
a VCL subroutine:
* If the failure occurs in ``vcl_init``, then the VCL load fails with
an error message.
* If the failure occurs in any other subroutine besides ``vcl_synth``,
then a ``VCL_Error`` message is written to the log, and control is
directed immediately to ``vcl_synth``, with ``resp.status`` set to
503 and ``resp.reason`` set to ``"VCL failed"``.
* If the failure occurs in ``vcl_synth``, then ``vcl_synth`` is
aborted, and the response line "503 VCL failed" is sent.
If the failure occurs in ``vcl_init``, then the VCL load fails, with
the VMOD's error message as the message for the load failure.
REQUIREMENTS
============
The VMOD requires Varnish versions 5.1.x. See the VMOD source
repository for versions that are compatible with other Varnish
versions.
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
versions that are compatible with other Varnish versions.
INSTALLATION
============
......
......@@ -37,7 +37,7 @@ AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
VARNISH_PREREQ([5.1.0], [5.1.3])
VARNISH_PREREQ([5.0.0], [5.0.0])
VARNISH_VMODS([selector])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
......
......@@ -30,7 +30,6 @@ varnish v1 -vcl {
set resp.http.N-4 = s.backend(4);
set resp.http.N-5 = s.backend(5);
set resp.http.N--1 = s.backend(-1);
set resp.http.N-0 = s.backend(0);
set resp.http.N-6 = s.backend(6);
......@@ -59,7 +58,6 @@ client c1 {
expect resp.http.N-4 == "b4"
expect resp.http.N-5 == "b5"
expect resp.http.N--1 == ""
expect resp.http.N-0 == ""
expect resp.http.N-6 == ""
......@@ -122,7 +120,6 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector error: s\.backend\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.backend\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.backend\(6\): set has 5 elements$}
expect * = End
} -run
......
......@@ -26,7 +26,6 @@ varnish v1 -vcl {
set resp.http.N-4 = s.element(4);
set resp.http.N-5 = s.element(5);
set resp.http.N--1 = s.element(-1);
set resp.http.N-0 = s.element(0);
set resp.http.N-6 = s.element(6);
......@@ -55,7 +54,6 @@ client c1 {
expect resp.http.N-4 == "quux"
expect resp.http.N-5 == "foobar"
expect resp.http.N--1 == ""
expect resp.http.N-0 == ""
expect resp.http.N-6 == ""
......@@ -118,7 +116,6 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector error: s\.element\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.element\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.element\(6\): set has 5 elements$}
expect * = End
} -run
......
......@@ -281,8 +281,6 @@ varnish v1 -vcl {
client c1 {
txreq
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
......
......@@ -1159,97 +1159,6 @@ client c1 {
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: fo2leShohj"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: thooL5peu4"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: aifaeW5dae"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: Aifiehoz3m"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: ahg1Va1hee"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: sowoh6saiX"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
txreq -hdr "Word: phahc0la8A"
rxresp
expect resp.status == 200
expect resp.http.Match == "false"
expect resp.http.N == "0"
expect resp.http.Which == "0"
expect resp.http.Which-Unique == resp.http.Which
expect resp.http.Which-Exact == "0"
expect resp.http.Which-First == "0"
expect resp.http.Which-Last == "0"
expect resp.http.Which-Shortest == "0"
expect resp.http.Which-Longest == "0"
} -run
varnish v1 -vcl {
......
......@@ -26,7 +26,6 @@ varnish v1 -vcl {
set resp.http.N-4 = s.re_match(req.http.Subject, 4);
set resp.http.N-5 = s.re_match(req.http.Subject, 5);
set resp.http.N--1 = s.re_match(req.http.Subject, -1);
set resp.http.N-0 = s.re_match(req.http.Subject, 0);
set resp.http.N-6 = s.re_match(req.http.Subject, 6);
......@@ -74,7 +73,6 @@ client c1 {
expect resp.http.N-4 == "false"
expect resp.http.N-5 == "false"
expect resp.http.N--1 == "false"
expect resp.http.N-0 == "false"
expect resp.http.N-6 == "false"
......@@ -203,7 +201,6 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector error: s\.re_match\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.re_match\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.re_match\(6\): set has 5 elements$}
expect * = End
} -run
......
......@@ -26,7 +26,6 @@ varnish v1 -vcl {
set resp.http.N-4 = s.string(4);
set resp.http.N-5 = s.string(5);
set resp.http.N--1 = s.string(-1);
set resp.http.N-0 = s.string(0);
set resp.http.N-6 = s.string(6);
......@@ -55,7 +54,6 @@ client c1 {
expect resp.http.N-4 == "xuuq"
expect resp.http.N-5 == "raboof"
expect resp.http.N--1 == ""
expect resp.http.N-0 == ""
expect resp.http.N-6 == ""
......@@ -118,7 +116,6 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector error: s\.string\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.string\(\) called without prior match$}
expect * = VCL_Error {^vmod selector error: s\.string\(6\): set has 5 elements$}
expect * = End
} -run
......
......@@ -45,12 +45,11 @@
#include "vcc_if.h"
#include "patricia.h"
#define VFAIL(ctx, fmt, ...) \
VRT_fail((ctx), "vmod selector failure: " fmt, __VA_ARGS__)
#define VERR(ctx, fmt, ...) \
VSLb((ctx)->vsl, SLT_VCL_Error, "vmod selector error: " fmt, \
__VA_ARGS__)
errmsg((ctx), "vmod selector error: " fmt, __VA_ARGS__)
#define VFAIL(ctx, fmt, ...) \
errmsg((ctx), "vmod selector failure: " fmt, __VA_ARGS__)
#define VERRNOMEM(ctx, fmt, ...) \
VERR((ctx), "out of space: " fmt, __VA_ARGS__)
......@@ -89,6 +88,51 @@ struct vmod_selector_set {
VCL_BOOL case_sensitive;
};
static void
errmsg(VRT_CTX, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if (ctx->vsl)
VSLbv(ctx->vsl, SLT_VCL_Error, fmt, args);
else
VSLv(SLT_VCL_Error, 0, fmt, args);
va_end(args);
if (ctx->method == VCL_MET_INIT) {
AN(ctx->msg);
va_start(args, fmt);
VSB_vprintf(ctx->msg, fmt, args);
VSB_putc(ctx->msg, '\n');
va_end(args);
VRT_handling(ctx, VCL_RET_FAIL);
}
}
static inline void
WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len)
{
const char *p = ptr;
assert(p >= ws->s && (p + len) <= ws->f);
}
static inline unsigned
WS_ReserveLumps(struct ws *ws, size_t sz)
{
unsigned u;
u = WS_Reserve(ws, 0);
u /= sz;
return (u);
}
static inline char*
WS_Front(const struct ws *ws)
{
return ws->f;
}
/* Event function */
int
......
......@@ -325,8 +325,7 @@ A regular expression in the ``regex`` parameter is compiled at VCL load
time. If the compile fails, then the VCL load fails with an error message.
Regular expressions are evaluated exactly as native regexen in VCL.
``.add()`` fails and invokes VCL failure (see `ERRORS`_) under the
following conditions:
``.add()`` fails under the following conditions:
* ``.add()`` is called any subroutine besides ``vcl_init``.
......@@ -336,6 +335,9 @@ following conditions:
* A regular expression in the ``regex`` parameter fails to compile.
See `ERRORS`_ below for details about error handling, for this and all
other methods.
Example::
sub vcl_init {
......@@ -653,33 +655,18 @@ Example::
ERRORS
======
The method documentation above refers to two kinds of failures: method
failure and VCL failure.
When a method fails, an error message is written to the Varnish log
with the ``VCL_Error`` tag, and the method returns an "error" value,
which depends on the return type, as documented above.
VCL failure has the same results as if ``return(fail)`` is called from
a VCL subroutine:
* If the failure occurs in ``vcl_init``, then the VCL load fails with
an error message.
* If the failure occurs in any other subroutine besides ``vcl_synth``,
then a ``VCL_Error`` message is written to the log, and control is
directed immediately to ``vcl_synth``, with ``resp.status`` set to
503 and ``resp.reason`` set to ``"VCL failed"``.
* If the failure occurs in ``vcl_synth``, then ``vcl_synth`` is
aborted, and the response line "503 VCL failed" is sent.
If the failure occurs in ``vcl_init``, then the VCL load fails, with
the VMOD's error message as the message for the load failure.
REQUIREMENTS
============
The VMOD requires Varnish versions 5.1.x. See the VMOD source
repository for versions that are compatible with other Varnish
versions.
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
versions that are compatible with other Varnish versions.
INSTALLATION
============
......
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