Basic implementation of zipflow.bundle, support empty zips

parent 4c416624
......@@ -27,7 +27,8 @@ AM_VTC_LOG_FLAGS = \
-p vmod_path="$(abs_builddir)/.libs:$(vmoddir):$(VARNISHAPI_VMODDIR)"
TESTS = \
vtc/vmod_zipflow.vtc
vtc/vmod_zipflow.vtc \
vtc/empty.vtc
# Documentation
......
......@@ -64,6 +64,7 @@ static const void *zipflow_priv = &zipflow_priv;
struct zipflow_task {
unsigned magic;
#define ZIPFLOW_TASK_MAGIC 0xaa175160
unsigned bundle:1;
char level;
VCL_STRING name;
unsigned mode;
......@@ -94,6 +95,7 @@ get_zipflow_task(VRT_CTX)
if (zft == NULL)
return (NULL);
zft->bundle = 1;
zft->level = default_level;
zft->name = "unnamed_file";
zft->mode = 0644;
......@@ -129,10 +131,15 @@ vmod_is_subreq(VRT_CTX)
VCL_VOID
vmod_bundle(VRT_CTX, VCL_BOOL toggle)
{
struct zipflow_task *zft;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
// XXX TODO
(void) toggle;
zft = get_zipflow_task(ctx);
if (zft == NULL)
return;
zft->bundle = toggle ? 1 : 0;
}
VCL_VOID
......@@ -253,7 +260,10 @@ vdp_zipflow_init(VRT_CTX, struct vdp_ctx *vdc, void **priv, struct objcore *oc)
return (1);
}
AZ(zip_log(zft->zip, vdc->vsl, vdp_zipflow_log));
AZ(zip_meta(zft->zip, zft->name, 3, zft->mode, zft->atime, zft->mtime));
if (zft->bundle) {
AZ(zip_meta(zft->zip, zft->name, 3, zft->mode,
zft->atime, zft->mtime));
}
AN(priv);
AZ(*priv);
......@@ -296,6 +306,10 @@ vdp_zipflow_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
AN(priv);
CAST_OBJ_NOTNULL(zft, *priv, ZIPFLOW_TASK_MAGIC);
if (zft->bundle == 0) {
(void) zip_close(zft->zip);
return (1);
}
r = zip_data(zft->zip, ptr, len, act == VDP_END);
if (r) {
VSLb(vdc->vsl, SLT_Error, "zip_data returned %d", r);
......
varnishtest "test vmod-zipflow: empty zip file"
server s1 {
rxreq
txresp -body "zip file content"
} -start
varnish v1 -vcl+backend {
import zipflow;
sub vcl_deliver {
zipflow.bundle(false);
zipflow.meta("filename", mode="444", atime=now, mtime=now - 1d);
set resp.filters += " zipflow";
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
} -run
shell -exit 1 -expect {zipfile is empty} \
"curl -svo t.zip -H 'Host: ${v1_addr}' http://${v1_addr}:${v1_port}/ && unzip -l 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