Hello.

Attached is a small patch that adds the req.method and bereq.method
attributes in VCL.

These are aliased to the req.request and bereq.request attributes, to be
more in harmony with the jargon used in HTTP in general.

Please consider this for inclusion in trunk.

-- 
Lasse Karstensen
>From 5be843237e352faf7d30a8982dfa3d9511abc9ef Mon Sep 17 00:00:00 2001
From: Lasse Karstensen <[email protected]>
Date: Fri, 4 Jan 2013 17:05:16 +0100
Subject: [PATCH] Add req.method and bereq.method

The HTTP specifications use the term request method, but in Varnish
this is usually called the request type.

This patch adds:
* req.method is an alias for req.request.
* bereq.method is an alias for bereq.request.

in the interest of harmonising VCL with HTTP jargon.
---
 bin/varnishd/cache/cache_vrt_var.c |    2 ++
 bin/varnishtest/tests/v00038.vtc   |   31 +++++++++++++++++++++++++++++++
 doc/sphinx/reference/vcl.rst       |   10 ++++++++--
 lib/libvcl/generate.py             |   12 ++++++++++++
 4 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 bin/varnishtest/tests/v00038.vtc

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 76c17d6..789426f 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -82,9 +82,11 @@ VRT_r_##obj##_##hdr(const struct req *req)			\
 }
 
 VRT_DO_HDR(req,   request,	req->http,		HTTP_HDR_REQ)
+VRT_DO_HDR(req,   method,	req->http,		HTTP_HDR_REQ)
 VRT_DO_HDR(req,   url,		req->http,		HTTP_HDR_URL)
 VRT_DO_HDR(req,   proto,	req->http,		HTTP_HDR_PROTO)
 VRT_DO_HDR(bereq, request,	req->busyobj->bereq,	HTTP_HDR_REQ)
+VRT_DO_HDR(bereq, method,	req->busyobj->bereq,	HTTP_HDR_REQ)
 VRT_DO_HDR(bereq, url,		req->busyobj->bereq,	HTTP_HDR_URL)
 VRT_DO_HDR(bereq, proto,	req->busyobj->bereq,	HTTP_HDR_PROTO)
 VRT_DO_HDR(obj,   proto,	req->obj->http,		HTTP_HDR_PROTO)
diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc
new file mode 100644
index 0000000..6734faf
--- /dev/null
+++ b/bin/varnishtest/tests/v00038.vtc
@@ -0,0 +1,31 @@
+varnishtest "test (req|bereq).method alias"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		set req.http.x-method = req.method;
+		if (req.request != req.method) {
+			error 500 "rainy day";
+		}
+	}
+	sub vcl_miss {
+		set req.http.x-foo = bereq.method;
+	}
+	sub vcl_deliver {
+		set resp.http.x-req-method = req.method;
+		set resp.http.x-req-request = req.request;
+		set resp.http.x-bereq-method = req.http.x-foo;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.x-req-method == "GET"
+	expect resp.http.x-req-request == "GET"
+	expect resp.http.x-bereq-method == "GET"
+} -run
diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst
index 325470c..b5f7017 100644
--- a/doc/sphinx/reference/vcl.rst
+++ b/doc/sphinx/reference/vcl.rst
@@ -620,7 +620,10 @@ server.port
   The port number of the socket on which the client connection was received.
 
 req.request
-  The request type (e.g. "GET", "HEAD").
+  The request method (e.g. "GET", "HEAD").
+
+req.method
+  The request method (e.g. "GET", "HEAD"). (alias)
 
 req.url
   The requested URL.
@@ -671,7 +674,10 @@ The following variables are available while preparing a backend
 request (either for a cache miss or for pass or pipe mode):
 
 bereq.request
-  The request type (e.g. "GET", "HEAD").
+  The request method (e.g. "GET", "HEAD").
+
+bereq.method
+  The request method (e.g. "GET", "HEAD"). (alias)
 
 bereq.url
   The requested URL.
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 45f015e..0254b89 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -145,6 +145,12 @@ sp_variables = (
 		( 'proc',),
 		'const struct req *'
 	),
+	('req.method',
+		'STRING',
+		( 'proc',),
+		( 'proc',),
+		'const struct req *'
+	),
 	('req.url',
 		'STRING',
 		( 'proc',),
@@ -241,6 +247,12 @@ sp_variables = (
 		( 'pipe', 'pass', 'miss', 'fetch',),
 		'const struct req *'
 	),
+	('bereq.method',
+		'STRING',
+		( 'pipe', 'pass', 'miss', 'fetch',),
+		( 'pipe', 'pass', 'miss', 'fetch',),
+		'const struct req *'
+	),
 	('bereq.url',
 		'STRING',
 		( 'pipe', 'pass', 'miss', 'fetch',),
-- 
1.7.10.4

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

Reply via email to