[6.0] 352201fb5 fix obj.hits in vcl_hit
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:08 UTC 2018
commit 352201fb5fd0e7f1070e4cefc49767bbf6c59981
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Aug 27 14:06:19 2018 +0200
fix obj.hits in vcl_hit
Fixes #2746
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index c902bee4c..748fe0a64 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -807,6 +807,8 @@ VRT_r_obj_hits(VRT_CTX)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
+ if (ctx->method == VCL_MET_HIT)
+ return (ctx->req->objcore->hits);
return (ctx->req->is_hit ? ctx->req->objcore->hits : 0);
}
diff --git a/bin/varnishtest/tests/v00013.vtc b/bin/varnishtest/tests/v00013.vtc
index 2772a2e18..52b81fc54 100644
--- a/bin/varnishtest/tests/v00013.vtc
+++ b/bin/varnishtest/tests/v00013.vtc
@@ -18,8 +18,14 @@ varnish v1 -vcl+backend {
return (pass);
}
}
+ sub vcl_hit {
+ set req.http.hit-hits = obj.hits;
+ }
sub vcl_deliver {
- set resp.http.foo = obj.hits;
+ set resp.http.deliver-hits = obj.hits;
+ if (req.http.hit-hits) {
+ set resp.http.hit-hits = req.http.hit-hits;
+ }
}
} -start
@@ -27,26 +33,31 @@ client c1 {
txreq
rxresp
expect resp.status == 200
- expect resp.http.foo == 0
+ expect resp.http.deliver-hits == 0
+ expect resp.http.hit-hits == <undef>
txreq
rxresp
expect resp.status == 200
- expect resp.http.foo == 1
+ expect resp.http.deliver-hits == 1
+ expect resp.http.hit-hits == 1
txreq -url /foo
rxresp
expect resp.status == 200
- expect resp.http.foo == 0
+ expect resp.http.deliver-hits == 0
+ expect resp.http.hit-hits == <undef>
delay .1
txreq
rxresp
expect resp.status == 200
- expect resp.http.foo == 2
+ expect resp.http.deliver-hits == 2
+ expect resp.http.hit-hits == 2
txreq -url /pass
rxresp
expect resp.status == 200
- expect resp.http.foo == 0
+ expect resp.http.deliver-hits == 0
+ expect resp.http.hit-hits == <undef>
} -run
More information about the varnish-commit
mailing list