Commit f5a8f3bf authored by Federico G. Schwindt's avatar Federico G. Schwindt

Change std.cache_req_body() to return BOOL

As discussed on irc.  OK'd by phk@.
parent 9871dd7e
......@@ -10,25 +10,22 @@ server s1 {
txresp -hdr "Foo: Foo" -body "56"
} -start
varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
varnish v1 -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
if (std.cache_req_body(1KB)) {
set req.http.stored = true;
} else {
set req.http.stored = false;
}
return (pass);
}
sub vcl_deliver {
if (resp.http.foo == "BAR") {
return (restart);
}
set resp.http.X-BodyBytes = req.http.X-BodyBytes;
set resp.http.stored = req.http.stored;
}
} -start
......@@ -36,7 +33,6 @@ varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
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"
......@@ -46,7 +42,7 @@ client c1 {
rxresp
expect resp.http.Foo == "Foo"
expect resp.bodylen == 2
expect resp.http.X-BodyBytes == 3
expect resp.http.stored == true
} -run
delay .1
......@@ -54,6 +50,7 @@ delay .1
client c1 {
txreq -req POST -nolen -hdr "Content-Length: 52"
delay .3
expect resp.http.stored == <undef>
} -run
delay .1
......@@ -67,12 +64,13 @@ client c1 {
txreq -url "/is_varnish_still_running"
rxresp
expect resp.status == 200
expect resp.http.X-BodyBytes == 0
expect resp.http.stored == true
} -run
client c2 {
txreq -req POST -nolen -hdr "Content-Length: 1025"
expect_close
expect resp.http.stored == <undef>
} -run
varnish v1 -stop
logexpect l1 -wait
......@@ -34,7 +34,8 @@ varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_recv {
std.cache_req_body(110B);
if (std.cache_req_body(110B)) {
}
}
}
......
......@@ -222,17 +222,19 @@ Description
Example
set req.url = std.querysort(req.url);
$Function VOID cache_req_body(BYTES size)
$Function BOOL cache_req_body(BYTES size)
Description
Cache the req.body if it is smaller than *size*.
Caches the request body if it is smaller than *size*. Returns
`true` if the body was cached, `false` otherwise.
Caching the req.body makes it possible to retry pass
operations (POST, PUT).
Normally the request body is not available after sending it to
the backend. By caching it is possible to retry pass operations,
e.g. POST and PUT.
Example
std.cache_req_body(1KB);
This will cache the req.body if its size is smaller than 1KB.
| if (std.cache_req_body(1KB)) {
| ...
| }
$Function STRING strstr(STRING s1, STRING s2)
......
......@@ -225,16 +225,15 @@ vmod_timestamp(VRT_CTX, VCL_STRING label)
}
}
VCL_VOID __match_proto__(td_std_cache_req_body)
VCL_BOOL __match_proto__(td_std_cache_req_body)
vmod_cache_req_body(VRT_CTX, VCL_BYTES size)
{
ssize_t result;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (size < 0)
size = 0;
result = VRT_CacheReqBody(ctx, (size_t)size);
VSLb(ctx->vsl, SLT_Debug, "VRT_CacheReqBody(%zd): %zd", (size_t)size, result);
if (VRT_CacheReqBody(ctx, (size_t)size) < 0)
return (0);
return (1);
}
VCL_STRING __match_proto__(td_std_strstr)
......
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