[master] 9bc756d Add VCL var sess.xid (VCL >= 4.1).
Geoff Simmons
geoff at uplex.de
Wed Mar 7 14:24:08 UTC 2018
commit 9bc756d0cc4981624ce8c1d933ef52c82d6e1731
Author: Geoff Simmons <geoff at uplex.de>
Date: Wed Mar 7 15:22:48 2018 +0100
Add VCL var sess.xid (VCL >= 4.1).
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index f5f305f..05f058a 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -648,7 +648,7 @@ VRT_DO_AGE_R(obj, ctx->req->objcore)
VRT_DO_AGE_R(beresp, ctx->bo->fetch_objcore)
/*--------------------------------------------------------------------
- * [be]req.xid
+ * [[be]req|sess].xid
*/
VCL_STRING
@@ -673,6 +673,20 @@ VRT_r_bereq_xid(VRT_CTX)
VXID(ctx->bo->vsl->wid)));
}
+VCL_STRING
+VRT_r_sess_xid(VRT_CTX)
+{
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ if (VALID_OBJ(ctx->req, REQ_MAGIC))
+ return (WS_Printf(ctx->req->http->ws, "%u",
+ VXID(ctx->req->sp->vxid)));
+
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+ return (WS_Printf(ctx->bo->bereq->ws, "%u",
+ VXID(ctx->bo->sp->vxid)));
+}
+
/*--------------------------------------------------------------------
* req fields
*/
diff --git a/bin/varnishtest/tests/t02000.vtc b/bin/varnishtest/tests/t02000.vtc
index cb7dc75..b3cbc1a 100644
--- a/bin/varnishtest/tests/t02000.vtc
+++ b/bin/varnishtest/tests/t02000.vtc
@@ -7,6 +7,10 @@ server s1 {
-hdr "H234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789I: foo" \
-hdr "Foo: H234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789I" \
-bodylen 10
+ rxreq
+ txresp
+ rxreq
+ txresp
} -start
varnish v1 -vcl+backend {
@@ -65,3 +69,34 @@ process p1 -stop
# shell {cat ${tmpdir}/vlog}
shell -match {1001 H2TxHdr c \[000006040000000000\]} \
{cat ${tmpdir}/vlog}
+
+# While we're here, test sess.xid over H2 as well
+
+varnish v1 -syntax 4.1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.http.B-Sess-XID = sess.xid;
+ }
+
+ sub vcl_deliver {
+ set resp.http.C-Sess-XID = sess.xid;
+ }
+}
+
+client c1 {
+ stream 7 {
+ txreq -url "/uncached"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.C-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.B-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
+ } -run
+ stream 9 {
+ txreq -url "/still_not_cached"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.C-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.B-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
+ } -run
+} -run
diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc
index 544240b..9a20422 100644
--- a/bin/varnishtest/tests/v00025.vtc
+++ b/bin/varnishtest/tests/v00025.vtc
@@ -3,6 +3,8 @@ varnishtest "More VCL coverage"
server s1 {
rxreq
txresp
+ rxreq
+ txresp
} -start
varnish v1 -syntax 4.0 -arg "-i J.F.Nobody" -vcl+backend {
@@ -91,3 +93,34 @@ client c1 {
txreq
rxresp
} -run
+
+varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'sess.xid' (Only available when 4.1 <= VCL syntax)} {
+ sub vcl_recv {
+ set req.http.Sess-XID = sess.xid;
+ }
+}
+
+varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'sess.xid' (Only available when 4.1 <= VCL syntax)} {
+ sub vcl_backend_fetch {
+ set bereq.http.Sess-XID = sess.xid;
+ }
+}
+
+varnish v1 -syntax 4.1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.http.B-Sess-XID = sess.xid;
+ }
+
+ sub vcl_deliver {
+ set resp.http.C-Sess-XID = sess.xid;
+ }
+}
+
+client c1 {
+ txreq -url "/uncached"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.C-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.B-Sess-XID ~ "^[0-9]+$"
+ expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
+} -run
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 37e88c9..7c18b36 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -1120,7 +1120,23 @@ now
When converted to STRING in expressions it returns
a formatted timestamp like `Tue, 20 Feb 2018 09:30:31 GMT`
-
+
+sess
+~~~~
+
+A session corresponds to the "conversation" that Varnish has with a
+single client connection, over which one or more request/response
+transactions may take place. It may comprise the traffic over an
+HTTP/1 keep-alive connection, or the multiplexed traffic over an
+HTTP/2 connection.
+
+sess.xid ``VCL >= 4.1``
+
+ Type: STRING
+
+ Readable from: client, backend
+
+ Unique ID of this session.
storage
~~~~~~~
More information about the varnish-commit
mailing list