Another patch while on the plane. As discussed at VDD15Q1 this exposes the
request body length via req.bodylen.
A few open questions / observations:
1. This will only set the length after std.cache_req_body(). We might want
to return content-length if std.cache_req_body() was not previously called.
I suppose some people might want to use it for other purposes than retrying
and if someone forgets calling cache_req_body() he/she might mistakenly
believe that there is no body. OTOH exposing this without curation might be
a bad idea.
2. This is only available in vcl_recv{}. Maybe it makes sense to expose
this to client and/or the backend side.
Comments? OKs?
From cf922810f556e82f0f28bb6cb8fd97fe3c34277a Mon Sep 17 00:00:00 2001
From: "Federico G. Schwindt" <[email protected]>
Date: Fri, 17 Apr 2015 14:23:06 +0100
Subject: [PATCH 2/2] Expose the request body length to vcl_recv{}
---
bin/varnishd/cache/cache_vrt_var.c | 11 +++++++++
bin/varnishtest/tests/c00069.vtc | 50 ++++++++++++++++++++++++++++++++++++++
lib/libvcc/generate.py | 8 ++++++
3 files changed, 69 insertions(+)
create mode 100644 bin/varnishtest/tests/c00069.vtc
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index e900726..d40969f 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -449,6 +449,17 @@ VRT_r_req_can_gzip(VRT_CTX)
/*--------------------------------------------------------------------*/
+double
+VRT_r_req_bodylen(VRT_CTX)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+ return (ctx->req->req_bodybytes);
+}
+
+/*--------------------------------------------------------------------*/
+
long
VRT_r_req_restarts(VRT_CTX)
{
diff --git a/bin/varnishtest/tests/c00069.vtc b/bin/varnishtest/tests/c00069.vtc
new file mode 100644
index 0000000..45d0bbf
--- /dev/null
+++ b/bin/varnishtest/tests/c00069.vtc
@@ -0,0 +1,50 @@
+varnishtest "Test req.bodylen"
+
+server s1 {
+ rxreq
+ expect req.http.x-bodylen == 0.000
+ txresp
+
+ rxreq
+ expect req.http.x-bodylen == 3.000
+ txresp
+
+ rxreq
+ expect req.http.x-bodylen == 26.000
+ txresp
+
+ rxreq
+ expect req.http.x-bodylen == 100.000
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import ${vmod_std};
+
+ sub vcl_recv {
+ if (req.url !~ "1") {
+ std.cache_req_body(1KB);
+ }
+ set req.http.x-bodylen = req.bodylen;
+ }
+} -start
+
+client c1 {
+ txreq -req POST -url /1 -body "foo"
+ rxresp
+ expect resp.status == 200
+
+ txreq -req POST -body "bar"
+ rxresp
+ expect resp.status == 200
+
+ txreq -req POST -gzipbody "baz"
+ rxresp
+ expect resp.status == 200
+
+ txreq -req POST -nolen -hdr "Transfer-encoding: chunked"
+ chunkedlen 100
+ chunkedlen 0
+ rxresp
+ expect resp.status == 200
+} -run
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 19da0e0..3c337aa 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -317,6 +317,14 @@ sp_variables = [
always (re)fetch from the backend.
"""
),
+ ('req.bodylen',
+ 'BYTES',
+ ( 'recv', ),
+ ( ), """
+ The length of the request body. Only available after
+ std.cache_req_body().
+ """
+ ),
('bereq',
'HTTP',
( 'backend',),
--
2.1.4
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev