Commit 811c0c54 authored by Nils Goroll's avatar Nils Goroll

Add test for support of PRIV_TASK in CLI induced VCL events.

Part of #2061
parent 4cd32f56
......@@ -11,13 +11,21 @@ varnish v1 -vcl+backend {
import debug;
import std;
sub vcl_init {
debug.test_priv_task("something");
debug.test_priv_task("to remember");
std.log(debug.test_priv_task());
}
sub vcl_recv {
set req.http.x0 = debug.test_priv_task(req.url);
debug.test_priv_task(req.url);
set req.http.x0 = debug.test_priv_task();
debug.test_priv_task("bazz");
}
sub vcl_deliver {
set resp.http.x0 = req.http.x0;
set resp.http.x1 = debug.test_priv_task("");
set resp.http.x1 = debug.test_priv_task();
}
sub vcl_backend_fetch {
......@@ -32,19 +40,37 @@ varnish v1 -vcl+backend {
}
} -start
logexpect l1 -v v1 -g raw -d 1 {
expect 0 0 CLI {^Rd vcl.load}
expect 0 = VCL_Log {^something to remember}
expect * 1002 Begin fetch$
expect * = VCL_call ^BACKEND_FETCH
expect 0 = VCL_Log ^foo
expect 0 = BereqHeader {^bx0: /foobar}
expect 0 = VCL_Log ^bar
expect * 1004 Begin fetch$
expect * = VCL_call ^BACKEND_FETCH
expect 0 = VCL_Log ^foo
expect 0 = BereqHeader {^bx0: /snafu}
expect 0 = VCL_Log ^bar
} -start
client c1 {
txreq -url /foobar
rxresp
expect resp.http.x0 == /foobar
expect resp.http.x1 == /foobar
expect resp.http.x1 == "/foobar bazz"
expect resp.http.bx0 == /foobar
expect resp.http.bx1 == /foobar
txreq -url /snafu
rxresp
expect resp.http.x0 == /snafu
expect resp.http.x1 == /snafu
expect resp.http.x1 == "/snafu bazz"
expect resp.http.bx0 == /snafu
expect resp.http.bx1 == /snafu
} -run
logexpect l1 -wait
......@@ -51,7 +51,7 @@ $Function VOID test_priv_vcl(PRIV_VCL)
Test function for VCL private pointers
$Function STRING test_priv_task(PRIV_TASK, STRING)
$Function STRING test_priv_task(PRIV_TASK, STRING s="")
Test function for TASK private pointers
......
......@@ -101,9 +101,19 @@ vmod_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (priv->priv == NULL) {
if (s == NULL || *s == '\0') {
return priv->priv;
} else if (priv->priv == NULL) {
priv->priv = strdup(s);
priv->free = free;
} else {
char *n = realloc(priv->priv,
strlen(priv->priv) + strlen(s) + 2);
if (n == NULL)
return NULL;
strcat(n, " ");
strcat(n, s);
priv->priv = n;
}
return (priv->priv);
}
......
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