-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi

Follow-up point from Hamburg: This exposes access to the top-level
request in VCL as req.top.*.

This is the VCL bits of Nils' commits 70e143c and 2b907d8.

req.top is thus the altered top-level request (i.e. what it looked
like after VCL processing), and not the original top-level request
(pre VCL processing).

- --
Dag Haavi Finstad
Software Developer | Varnish Software
Mobile: +47 476 64 134
We Make Websites Fly!

-----BEGIN PGP SIGNATURE-----
Version: OpenPGP.js v0.9.0
Comment: http://openpgpjs.org

wsBcBAEBCAAQBQJVAB8FCRBYSj6/5wXNzQAASPYH/R1ZT3hv8BxVtQe2bKfQ
zuZzWuV3JOAownZ4xwgi49ovLMc3dIIRjLCtPIWdDZILQQxbFhCIP4ZxocqU
nBt4x6HIHviEBfVVVQ2t10+n+v8toRTYMQKw6tlCzBc99Iq7xUGv04xtm5Tl
vXLkyZcGVYkU56Id53TA+RHETAa9400uCPG2ekXtJ0AhplmLfaxiKqAdvKPm
EG3widApRvCufh6XKzOzCvFncTCJegN06ikN0pOeC2Vl0IN4bfV9+WPJQce7
2iIivSvFNf6+DSVzKl/dHEmTopEc5bG4wIc4Ic+ODmDlKHJ8z+g8sMPRRZJ3
37cntu03YsAR2P5N+IoOElg=
=5ViT
-----END PGP SIGNATURE-----
From 970b029165e843cb503e192a1543b65f18661418 Mon Sep 17 00:00:00 2001
From: Dag Haavi Finstad <[email protected]>
Date: Wed, 11 Mar 2015 11:41:54 +0100
Subject: [PATCH] Add (read-only) access to req.top.{method,url,proto,http.*}.

This exposes VCL access to the (altered) top level request.
---
 bin/varnishd/cache/cache_vcl.c     |  1 +
 bin/varnishd/cache/cache_vrt.c     |  3 ++
 bin/varnishd/cache/cache_vrt_var.c |  4 ++
 bin/varnishtest/tests/e00029.vtc   | 76 ++++++++++++++++++++++++++++++++++++++
 include/vrt.h                      |  4 +-
 lib/libvcc/generate.py             | 33 ++++++++++++++++-
 6 files changed, 119 insertions(+), 2 deletions(-)
 create mode 100644 bin/varnishtest/tests/e00029.vtc

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index a5a7da4..6262771 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -475,6 +475,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		vsl = req->vsl;
 		ctx.vcl = req->vcl;
 		ctx.http_req = req->http;
+		ctx.http_req_top = req->top->http;
 		ctx.http_resp = req->resp;
 		ctx.req = req;
 		ctx.now = req->t_prev;
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 6851bc0..316bd20 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -96,6 +96,9 @@ VRT_selecthttp(VRT_CTX, enum gethdr_e where)
 	case HDR_REQ:
 		hp = ctx->http_req;
 		break;
+	case HDR_REQ_TOP:
+		hp = ctx->http_req_top;
+		break;
 	case HDR_BEREQ:
 		hp = ctx->http_bereq;
 		break;
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index a53c07a..3e1aa97 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -120,6 +120,10 @@ VRT_HDR_LR(req,    method,	HTTP_HDR_METHOD)
 VRT_HDR_LR(req,    url,		HTTP_HDR_URL)
 VRT_HDR_LR(req,    proto,	HTTP_HDR_PROTO)
 
+VRT_HDR_R(req_top,    method,	HTTP_HDR_METHOD)
+VRT_HDR_R(req_top,    url,	HTTP_HDR_URL)
+VRT_HDR_R(req_top,    proto,	HTTP_HDR_PROTO)
+
 VRT_HDR_LR(resp,   proto,	HTTP_HDR_PROTO)
 VRT_HDR_LR(resp,   reason,	HTTP_HDR_REASON)
 VRT_STATUS_L(resp)
diff --git a/bin/varnishtest/tests/e00029.vtc b/bin/varnishtest/tests/e00029.vtc
new file mode 100644
index 0000000..bd04ce1
--- /dev/null
+++ b/bin/varnishtest/tests/e00029.vtc
@@ -0,0 +1,76 @@
+varnishtest "Test req.top.* in an ESI context"
+
+varnish v1 -errvcl {Variable 'req.top.url' is read only.} {
+	sub vcl_recv {
+		set req.top.url = "/foo";
+	}
+}
+
+server s1 {
+	rxreq
+	expect req.http.top-url == "/"
+	expect req.http.top-method == "GET"
+	expect req.http.top-proto == "HTTP/1.1"
+	expect req.http.top-foo == "bar"
+	txresp -body {
+		<html>
+		Before include
+		<esi:include src="/a"/>
+		<esi:include src="/b"/>
+		After include
+		</html>
+	}
+
+	rxreq
+	expect req.url == "/a1"
+	expect req.http.top-url == "/"
+	expect req.http.top-method == "GET"
+	expect req.http.top-proto == "HTTP/1.1"
+	expect req.http.top-foo == "bar"
+	txresp -body {
+		Included file
+		<esi:include src="/c"/>
+	}
+
+	rxreq
+	expect req.http.top-url == "/"
+	expect req.http.top-method == "GET"
+	expect req.http.top-proto == "HTTP/1.1"
+	expect req.http.top-foo == "bar"
+	expect req.url == "/b1"
+	txresp
+
+	rxreq
+	expect req.http.top-url == "/"
+	expect req.http.top-method == "GET"
+	expect req.http.top-proto == "HTTP/1.1"
+	expect req.http.top-foo == "bar"
+	expect req.url == "/c2"
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.esi_level > 0) {
+			set req.url = req.url + req.esi_level;
+		} else {
+			set req.http.foo = "bar";
+		}
+
+		set req.http.top-url = req.top.url;
+		set req.http.top-method = req.top.method;
+		set req.http.top-proto = req.top.proto;
+		set req.http.top-foo = req.top.http.foo;
+	}
+	sub vcl_backend_response {
+		set beresp.do_esi = true;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run
+
+varnish v1 -expect esi_errors == 0
diff --git a/include/vrt.h b/include/vrt.h
index 60a0f14..e623042 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -99,6 +99,7 @@ struct vrt_ctx {
 
 	struct req			*req;
 	struct http			*http_req;
+	struct http			*http_req_top;
 	struct http			*http_resp;
 
 	struct busyobj			*bo;
@@ -128,7 +129,8 @@ struct vmod_data {
 
 /***********************************************************************/
 
-enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };
+enum gethdr_e { HDR_REQ, HDR_REQ_TOP, HDR_RESP, HDR_OBJ, HDR_BEREQ,
+		HDR_BERESP };
 
 struct gethdr_s {
 	enum gethdr_e	where;
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 871b8bc..6e59ca8 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -301,6 +301,34 @@ sp_variables = [
 		always (re)fetch from the backend.
 		"""
 	),
+        ('req.top.method',
+		'STRING',
+		( 'client',),
+		(), """
+		The request type of the top-level request (e.g. "GET", "HEAD").
+		"""
+	),
+	('req.top.url',
+		'STRING',
+		( 'client',),
+		(), """
+		The requested URL for the top-level request.
+		"""
+	),
+        ('req.top.http.',
+		'HEADER',
+		( 'client',),
+		(), """
+		The corresponding HTTP header of the top-level request.
+		"""
+	),
+        ('req.top.proto',
+		'STRING',
+		( 'client',),
+		(), """
+		The HTTP protocol version used by the client for the top-level request.
+		"""
+	),
 	('bereq',
 		'HTTP',
 		( 'backend',),
@@ -1094,7 +1122,10 @@ def one_var(nm, spec):
 		fo.write('\t    NULL,\t/* No reads allowed */\n')
 	elif typ == "HEADER":
 		fo.write('\t    "HDR_')
-		fo.write(nm.split(".")[0].upper())
+		if nm.startswith("req.top"):
+			fo.write("REQ_TOP")
+		else:
+			fo.write(nm.split(".")[0].upper())
 		fo.write('",\n')
 	else:
 		fo.write('\t    "VRT_r_%s(ctx)",\n' % cnam)
-- 
2.1.4

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to