[master] 6f57a2190 Add req.is_hitmiss and req.is_hitpass
Nils Goroll
nils.goroll at uplex.de
Mon Dec 3 21:47:08 UTC 2018
commit 6f57a2190283aa812482157d713ac51d17a529e6
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
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 477e4f468..dd77bf033 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -509,12 +509,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);
}
@@ -815,6 +818,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 a3d500a28..f80b52ef7 100644
Binary files a/doc/changes.rst and b/doc/changes.rst differ
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index c0007a761..c962f3147 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