Commit a7be4ff8 authored by Nils Goroll's avatar Nils Goroll

straighten VRB_Cache / VRT_CacheReqBody corner cases, improve test

- As VRB_Cache returns -1 upon error, so should VRT_CacheReqBody
- 0 is a valid body size, so it shouldn't be used for signalling errors
- VRB_Cache should return number of bytes when already cached
- VRB_Cache: return -1 on insufficient bytes also
parent 84de64d5
......@@ -199,7 +199,7 @@ VRB_Cache(struct req *req, ssize_t maxsize)
assert (req->req_step == R_STP_RECV);
switch(req->req_body_status) {
case REQ_BODY_CACHED:
return (0);
return (req->req_bodybytes);
case REQ_BODY_FAIL:
return (-1);
case REQ_BODY_NONE:
......@@ -279,5 +279,5 @@ VRB_Cache(struct req *req, ssize_t maxsize)
req->req_body_status = REQ_BODY_FAIL;
}
VSLb_ts_req(req, "ReqBody", VTIM_real());
return (vfps == VFP_END ? req->req_bodybytes : 0);
return (vfps == VFP_END ? req->req_bodybytes : -1);
}
......@@ -486,7 +486,7 @@ VRT_CacheReqBody(VRT_CTX, long long maxsize)
if (ctx->method != VCL_MET_RECV) {
VSLb(ctx->vsl, SLT_VCL_Error,
"req.body can only be cached in vcl_recv{}");
return (0);
return (-1);
}
return (VRB_Cache(ctx->req, maxsize));
}
......
......@@ -10,20 +10,35 @@ server s1 {
txresp -status 200 -hdr "Foo: Foo" -body "56"
} -start
varnish v1 -vcl+backend {
varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
import ${vmod_std};
sub vcl_recv {
std.cache_req_body(1KB);
C{
const struct gethdr_s HDR_REQ_X_BodyBytes =
{ HDR_REQ, "\014X-BodyBytes:"};
VRT_SetHdr(ctx, &HDR_REQ_X_BodyBytes,
VRT_INT_string(ctx, VRT_CacheReqBody(ctx, 1024)),
vrt_magic_string_end);
}C
return (pass);
}
sub vcl_deliver {
if (resp.http.foo == "BAR") {
return (restart);
}
set resp.http.X-BodyBytes = req.http.X-BodyBytes;
}
} -start
# check log for the aborted POST
logexpect l1 -v v1 {
expect * 1006 Begin
expect * = FetchError "^straight insufficient bytes"
expect * = ReqHeader "^X-BodyBytes: -1"
} -start
varnish v1 -cliok "param.set debug +syncvsl"
client c1 {
......@@ -31,6 +46,7 @@ client c1 {
rxresp
expect resp.http.Foo == "Foo"
expect resp.bodylen == 2
expect resp.http.X-BodyBytes == 3
} -run
delay .1
......@@ -51,4 +67,7 @@ client c1 {
txreq -url "/is_varnish_still_running"
rxresp
expect resp.status == 200
expect resp.http.X-BodyBytes == 0
} -run
varnish v1 -stop
logexpect l1 -wait
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