Make subreq() work

parent 99a7d77f
......@@ -25,6 +25,16 @@ AC_ARG_WITH([rst2man],
VARNISH_PREREQ([6.0.0])
VARNISH_VMODS([zipflow])
AC_ARG_VAR([VARNISHSRC], [path to Varnish source])
if test "x$VARNISHSRC" = x; then
AC_MSG_FAILURE([Need VARNISHSRC])
fi
VARNISHSRC_CFLAGS="$VARNISHAPI_CFLAGS \
-I$VARNISHSRC/include \
-I$VARNISHSRC/bin/varnishd \
-I$VARNISHSRC/lib/libvsc"
AC_SUBST([VARNISHSRC_CFLAGS])
AC_CONFIG_FILES([
Makefile
src/Makefile
......
AM_CFLAGS = $(VARNISHAPI_CFLAGS) $(ZLIB_CFLAGS) -I../foreign/zipflow
AM_CFLAGS = $(VARNISHSRC_CFLAGS) $(ZLIB_CFLAGS) -I../foreign/zipflow
# Modules
......@@ -29,7 +29,9 @@ AM_VTC_LOG_FLAGS = \
TESTS = \
vtc/vmod_zipflow.vtc \
vtc/empty.vtc \
vtc/coverage.vtc
vtc/coverage.vtc \
vtc/sub.vtc \
vtc/sub-coalesce.vtc
# Documentation
......
......@@ -3,6 +3,7 @@
-efile(766, vmod_compat.h)
-e717 // do ... while(0)
-e663 // array to pointer
-ecall(835, dlopen)
-e801 // goto
......@@ -19,4 +20,6 @@
// assert constructors not referenced
-esym(528, assert_*)
-emacro(747, WS_TASK_ALLOC_OBJ)
\ No newline at end of file
-emacro(747, WS_TASK_ALLOC_OBJ)
-emacro(527, WRONG)
-emacro(506, VSTAILQ_FOREACH_SAFE)
\ No newline at end of file
This diff is collapsed.
......@@ -37,17 +37,25 @@ Example
set resp.filters += " zipflow";
}
$Function VOID subreq(STRING url)
$Function VOID subreq(STRING url, STRING host=0)
$Restrict client
Issue a sub requets to *url* when the VDP runs, similar to ESI
Issue a sub requets to *host*/*uri* when the VDP runs, similar to ESI
processing.
This function can be called any number of times. The sub request can
be identified using `zipflow.is_subreq()`_. In the sub request,
`zipflow.set_level()`_ and `zipflow.meta()`_ should be used to control
how zipflow handles the body.
If *host* is omitted (default), it is taken from the parent request.
This function can be called any number of times to add multiple
files, it can eben be called from a sub request, which is to say that
more files can be added while requests for files are processed.
The sub request can be identified using `zipflow.is_subreq()`_. In the
sub request, `zipflow.set_level()`_ and `zipflow.meta()`_ should be
used to control how zipflow handles the body.
Only sub requests with reponse status 200 will be included in the
resulting zip file.
$Function BOOL is_subreq()
......
varnishtest "vmod-zipflow sub request / race & waitinglist"
feature cmd "type curl && type unzip && echo 'foo' grep -P '^foo'"
server s1 {
rxreq
expect req.url == "/file1"
txresp -gziplevel 1 -gziplen 10240
rxreq
expect req.url == "/file2"
txresp -bodylen 20480
} -start
varnish v1 -vcl+backend {
import zipflow;
sub vcl_recv {
zipflow.set_level(0);
if (zipflow.is_subreq()) {
return (hash);
}
return (synth(200));
}
sub vcl_synth {
synthetic("top zip");
zipflow.meta(name="top");
zipflow.subreq("/file1");
zipflow.subreq("/file2");
set resp.filters += " zipflow";
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.bodylen == 31102
} -start
client c2 {
txreq
rxresp
expect resp.status == 200
expect resp.bodylen == 31102
} -start
client c3 {
txreq
rxresp
expect resp.status == 200
expect resp.bodylen == 31102
} -start
client c4 {
txreq
rxresp
expect resp.status == 200
expect resp.bodylen == 31102
} -start
client c1 -wait
client c2 -wait
client c3 -wait
client c4 -wait
\ No newline at end of file
varnishtest "vmod-zipflow sub request"
feature cmd "type curl && type unzip && echo 'foo' grep -P '^foo'"
varnish v1 -vcl {
import zipflow;
import std;
backend proforma none;
sub vcl_recv {
return (synth(200));
}
sub synth_top {
synthetic("top zip");
zipflow.meta(name="top");
zipflow.subreq("/file1");
zipflow.subreq("/file2");
set resp.filters += " zipflow";
}
sub synth_sub {
synthetic("sub " + req.url);
}
sub vcl_synth {
if (zipflow.is_subreq()) {
call synth_sub;
if (req.url == "/file1") {
zipflow.meta(name="file1.changed");
zipflow.subreq("/file3");
} else
if (req.url == "/file3") {
zipflow.subreq("/file4");
}
} else {
call synth_top;
}
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
} -run
# all default
shell "curl -so t.zip -H 'Host: ${v1_addr}' http://${v1_addr}:${v1_port}/ && unzip -Z t.zip"
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