[6.0] 7519d5330 Add req.is_hitmiss and req.is_hitpass
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:09 UTC 2019
commit 7519d53304e2b2b491060bfa89aab48141689cc2
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Dec 3 22:43:50 2018 +0100
Add req.is_hitmiss and req.is_hitpass
Closes #2743
Conflicts:
doc/changes.rst
doc/changes.rst was considered binary in master, it won't be in 6.0 so
there will be no need to pick a1d2db691eef3ee09ec30c591006c9aa2a5026f5
too.
Refs a1d2db691eef3ee09ec30c591006c9aa2a5026f5
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 85af28381..b4bcc71ce 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -522,12 +522,15 @@ cnt_lookup(struct worker *wrk, struct req *req)
req->objcore = busy;
req->stale_oc = oc;
req->req_step = R_STP_MISS;
+ if (lr == HSH_HITMISS)
+ req->is_hitmiss = 1;
return (REQ_FSM_MORE);
}
if (lr == HSH_HITPASS) {
AZ(busy);
AZ(oc);
req->req_step = R_STP_PASS;
+ req->is_hitpass = 1;
return (REQ_FSM_MORE);
}
@@ -828,6 +831,8 @@ cnt_recv_prep(struct req *req, const char *ci)
req->vdc->retval = 0;
req->is_hit = 0;
+ req->is_hitmiss = 0;
+ req->is_hitpass = 0;
}
/*--------------------------------------------------------------------
* We have a complete request, set everything up and start it.
diff --git a/bin/varnishtest/tests/c00014.vtc b/bin/varnishtest/tests/c00014.vtc
index a0dbf5493..6fc238813 100644
--- a/bin/varnishtest/tests/c00014.vtc
+++ b/bin/varnishtest/tests/c00014.vtc
@@ -16,6 +16,12 @@ server s1 {
} -start
varnish v1 -vcl+backend {
+ sub vcl_miss {
+ set req.http.hitmiss = req.is_hitmiss;
+ }
+ sub vcl_deliver {
+ set resp.http.hitmiss = req.http.hitmiss;
+ }
sub vcl_backend_response {
set beresp.do_stream = false;
set beresp.uncacheable = true;
@@ -28,6 +34,7 @@ client c1 {
expect resp.status == 200
expect resp.bodylen == 12
expect resp.http.x-varnish == "1001"
+ expect resp.http.hitmiss == "false"
} -start
barrier b1 sync
@@ -39,6 +46,7 @@ client c2 {
expect resp.status == 200
expect resp.bodylen == 6
expect resp.http.x-varnish == "1004"
+ expect resp.http.hitmiss == "true"
} -run
client c1 -wait
diff --git a/bin/varnishtest/tests/c00081.vtc b/bin/varnishtest/tests/c00081.vtc
index b08fa3250..ffd344080 100644
--- a/bin/varnishtest/tests/c00081.vtc
+++ b/bin/varnishtest/tests/c00081.vtc
@@ -12,10 +12,10 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_miss {
- set req.http.miss = "True";
+ set req.http.miss = true;
}
sub vcl_pass {
- set req.http.pass = "True";
+ set req.http.hitpass = req.is_hitpass;
}
sub vcl_backend_response {
@@ -24,7 +24,7 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
set resp.http.miss = req.http.miss;
- set resp.http.pass = req.http.pass;
+ set resp.http.hitpass = req.http.hitpass;
}
} -start
@@ -36,17 +36,17 @@ logexpect l1 -v v1 -g vxid {
client c1 {
txreq
rxresp
- expect resp.http.miss == True
+ expect resp.http.miss == true
txreq
rxresp
- expect resp.http.pass == True
+ expect resp.http.hitpass == true
delay 3
txreq
rxresp
- expect resp.http.miss == True
+ expect resp.http.miss == true
} -run
logexpect l1 -wait
diff --git a/doc/changes.rst b/doc/changes.rst
index 5ac9da18f..94583e701 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -34,6 +34,10 @@ Varnish Cache 6.0.3 (unreleased)
renamed the red/black tree macros from ``VRB_*`` to ``VRBT_*``
to disambiguate from the acronym for Varnish Request Body.
+* added ``req.is_hitmiss`` and ``req.is_hitpass`` (2743_)
+
+.. _2743: https://github.com/varnishcache/varnish-cache/issues/2743
+
================================
Varnish Cache 6.0.2 (2018-11-07)
================================
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 4efbdff39..e8c04d928 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -391,6 +391,21 @@ req.hash_always_miss
This is useful to force-update the cache without invalidating
existing entries in case the fetch fails.
+req.is_hitmiss
+
+ Type: BOOL
+
+ Readable from: client
+
+ If this request resulted in a hitmiss
+
+req.is_hitpass
+
+ Type: BOOL
+
+ Readable from: client
+
+ If this request resulted in a hitpass
req_top.method
diff --git a/include/tbl/req_flags.h b/include/tbl/req_flags.h
index e23b9c1a2..2c0dbe803 100644
--- a/include/tbl/req_flags.h
+++ b/include/tbl/req_flags.h
@@ -34,6 +34,8 @@ REQ_FLAG(disable_esi, 0, 0, "")
REQ_FLAG(hash_ignore_busy, 1, 1, "")
REQ_FLAG(hash_always_miss, 1, 1, "")
REQ_FLAG(is_hit, 0, 0, "")
+REQ_FLAG(is_hitmiss, 1, 0, "")
+REQ_FLAG(is_hitpass, 1, 0, "")
REQ_FLAG(waitinglist, 0, 0, "")
REQ_FLAG(want100cont, 0, 0, "")
REQ_FLAG(late100cont, 0, 0, "")
More information about the varnish-commit
mailing list