Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
f5a8f3bf
Commit
f5a8f3bf
authored
Feb 16, 2016
by
Federico G. Schwindt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change std.cache_req_body() to return BOOL
As discussed on irc. OK'd by phk@.
parent
9871dd7e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
26 deletions
+26
-26
c00055.vtc
bin/varnishtest/tests/c00055.vtc
+11
-13
c00067.vtc
bin/varnishtest/tests/c00067.vtc
+2
-1
vmod.vcc
lib/libvmod_std/vmod.vcc
+9
-7
vmod_std.c
lib/libvmod_std/vmod_std.c
+4
-5
No files found.
bin/varnishtest/tests/c00055.vtc
View file @
f5a8f3bf
...
...
@@ -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
bin/varnishtest/tests/c00067.vtc
View file @
f5a8f3bf
...
...
@@ -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)) {
}
}
}
...
...
lib/libvmod_std/vmod.vcc
View file @
f5a8f3bf
...
...
@@ -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)
...
...
lib/libvmod_std/vmod_std.c
View file @
f5a8f3bf
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment