The attached patch will add read-only access to these new variables which
indicate if the backend response or object originated from a pass request.
See vcl.rst for more details.
Index: varnish-cache/doc/sphinx/reference/vcl.rst
===================================================================
--- varnish-cache/doc/sphinx/reference/vcl.rst (revision 5518)
+++ varnish-cache/doc/sphinx/reference/vcl.rst (working copy)
@@ -12,8 +12,8 @@
:Author: Poul-Henning Kamp
:Author: Kristian Lyngstøl
:Author: Per Buer
-:Date: 2010-06-02
-:Version: 1.0
+:Date: 2010-11-07
+:Version: 1.0.1
:Manual section: 7
DESCRIPTION
@@ -647,6 +647,14 @@
beresp.cacheable is writable.
+beresp.pass
+ True if the response originated from a pass request, either explicit
+ or via a hit for pass (an object with obj.pass was found in the cache).
+
+ In contrast to beresp.cacheable, this variable is read-only and only
+ determined by whether or not return(pass) as been called at some
+ point before vcl_fetch.
+
beresp.ttl
The object's remaining time to live, in seconds. beresp.ttl is writable.
@@ -667,6 +675,19 @@
True if the object had beresp.cacheable. Unless you've forced delivery
in your VCL obj.cacheable will always be true.
+ Only available in vcl_hit.
+
+obj.pass
+ True if this object resulted from a pass request or has been marked
+ to trigger passes for future requests (hit-for-pass) by return(pass)
+ in vcl_fetch.
+
+ Only available in vcl_deliver and vcl_error.
+
+ For objects with obj.pass == true, vcl_hit will never get called
+ (hit-for-pass), so consequently this variable is not available in
+ vcl_hit.
+
obj.ttl
The object's remaining time to live, in seconds. obj.ttl is writable.
Index: varnish-cache/lib/libvcl/generate.py
===================================================================
--- varnish-cache/lib/libvcl/generate.py (revision 5518)
+++ varnish-cache/lib/libvcl/generate.py (working copy)
@@ -315,6 +315,12 @@
( ),
'const struct sess *'
),
+ ('beresp.pass',
+ 'BOOL',
+ ( 'fetch',),
+ ( ),
+ 'const struct sess *'
+ ),
('obj.proto',
'STRING',
( 'hit', 'error',),
@@ -369,6 +375,13 @@
( ),
'const struct sess *'
),
+ # hit will never see a hit-for-pass obj
+ ('obj.pass',
+ 'BOOL',
+ ( 'deliver', 'error',),
+ ( ),
+ 'const struct sess *'
+ ),
('resp.proto',
'STRING',
( 'deliver',),
Index: varnish-cache/bin/varnishtest/tests/c00010.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/c00010.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/c00010.vtc (working copy)
@@ -15,6 +15,12 @@
sub vcl_hit {
return(pass);
}
+ sub vcl_fetch {
+ set beresp.http.beresp.pass = beresp.pass;
+ }
+ sub vcl_deliver {
+ set resp.http.obj.pass = obj.pass;
+ }
} -start
client c1 {
@@ -23,11 +29,15 @@
expect resp.status == 200
expect resp.http.content-length == 6
expect resp.http.x-varnish == "1001"
+ expect resp.http.beresp.pass == false
+ expect resp.http.obj.pass == false
txreq -url "/foo"
rxresp
expect resp.status == 200
expect resp.http.content-length == 7
expect resp.http.x-varnish == "1002"
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
}
client c1 -run
Index: varnish-cache/bin/varnishtest/tests/c00012.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/c00012.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/c00012.vtc (working copy)
@@ -15,6 +15,12 @@
sub vcl_miss {
return(pass);
}
+ sub vcl_fetch {
+ set beresp.http.beresp.pass = beresp.pass;
+ }
+ sub vcl_deliver {
+ set resp.http.obj.pass = obj.pass;
+ }
} -start
client c1 {
@@ -23,11 +29,15 @@
expect resp.status == 200
expect resp.http.content-length == 6
expect resp.http.x-varnish == "1001"
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
txreq -url "/foo"
rxresp
expect resp.status == 200
expect resp.http.content-length == 7
expect resp.http.x-varnish == "1002"
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
}
client c1 -run
Index: varnish-cache/bin/varnishtest/tests/r00425.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/r00425.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/r00425.vtc (working copy)
@@ -20,15 +20,32 @@
-body "33333n"
} -start
-varnish v1 -vcl+backend { } -start
+varnish v1 -vcl+backend {
+ sub vcl_fetch {
+ set beresp.http.beresp.pass = beresp.pass;
+## from default.vcl
+# if (beresp.http.Set-Cookie) {
+# return (pass);
+# }
+ }
+ sub vcl_deliver {
+ set resp.http.obj.pass = obj.pass;
+ }
+} -start
client c1 {
txreq
rxresp
+ expect resp.http.beresp.pass == false
+ expect resp.http.obj.pass == true
txreq
rxresp
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
txreq
rxresp
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
} -run
varnish v1 -expect cache_hitpass == 2
Index: varnish-cache/bin/varnishtest/tests/b00002.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/b00002.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/b00002.vtc (working copy)
@@ -11,12 +11,20 @@
sub vcl_recv {
return(pass);
}
+ sub vcl_fetch {
+ set beresp.http.beresp.pass = beresp.pass;
+ }
+ sub vcl_deliver {
+ set resp.http.obj.pass = obj.pass;
+ }
} -start
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
+ expect resp.http.beresp.pass == true
+ expect resp.http.obj.pass == true
} -run
# Give varnish a chance to update stats
Index: varnish-cache/bin/varnishtest/tests/c00011.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/c00011.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/c00011.vtc (working copy)
@@ -4,30 +4,47 @@
server s1 {
rxreq
- expect req.url == "/foo"
+ expect req.url == "/foo1"
txresp -body foobar
rxreq
- expect req.url == "/foo"
+ expect req.url == "/foo2"
txresp -body foobar1
} -start
varnish v1 -vcl+backend {
+ sub vcl_hash {
+ hash_data("foo");
+ return (hash);
+ }
sub vcl_fetch {
- return(pass);
+ set beresp.http.beresp.pass = req.url + " " + beresp.pass;
+ if (req.url == "/foo1") {
+ return(pass);
+ }
}
+ sub vcl_deliver {
+ set resp.http.obj.pass = req.url + " " + obj.pass;
+ }
} -start
client c1 {
- txreq -url "/foo"
+ txreq -url "/foo1"
rxresp
expect resp.status == 200
expect resp.http.content-length == 6
expect resp.http.x-varnish == "1001"
- txreq -url "/foo"
+ expect resp.http.beresp.pass == "/foo1 false"
+ expect resp.http.obj.pass == "/foo1 true"
+ txreq -url "/foo2"
rxresp
expect resp.status == 200
expect resp.http.content-length == 7
expect resp.http.x-varnish == "1002"
+ expect resp.http.beresp.pass == "/foo2 true"
+ expect resp.http.obj.pass == "/foo2 true"
}
client c1 -run
+
+varnish v1 -expect cache_hitpass == 1
+
Index: varnish-cache/bin/varnishtest/tests/b00003.vtc
===================================================================
--- varnish-cache/bin/varnishtest/tests/b00003.vtc (revision 5518)
+++ varnish-cache/bin/varnishtest/tests/b00003.vtc (working copy)
@@ -7,13 +7,22 @@
txresp -hdr "Connection: close" -body "012345\n"
} -start
-varnish v1 -vcl+backend { } -start
+varnish v1 -vcl+backend {
+ sub vcl_fetch {
+ set beresp.http.beresp.pass = beresp.pass;
+ }
+ sub vcl_deliver {
+ set resp.http.obj.pass = obj.pass;
+ }
+} -start
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1001"
+ expect resp.http.beresp.pass == false
+ expect resp.http.obj.pass == false
} -run
client c2 {
@@ -21,6 +30,8 @@
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1002 1001"
+ expect resp.http.beresp.pass == false
+ expect resp.http.obj.pass == false
} -run
# Give varnish a chance to update stats
Index: varnish-cache/bin/varnishd/cache_vrt_var.c
===================================================================
--- varnish-cache/bin/varnishd/cache_vrt_var.c (revision 5518)
+++ varnish-cache/bin/varnishd/cache_vrt_var.c (working copy)
@@ -257,6 +257,13 @@
return (sp->wrk->ttl - sp->t_req);
}
+unsigned
+VRT_r_beresp_pass(const struct sess *sp)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ return (sp->pass == 1);
+}
+
/*--------------------------------------------------------------------*/
#define BEREQ_TIMEOUT(which) \
@@ -364,6 +371,15 @@
VOBJ(unsigned, cacheable, cacheable)
+unsigned
+VRT_r_obj_pass(const struct sess *sp)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
+ return ((sp->obj->objcore == NULL) || (sp->obj->objcore->flags &
OC_F_PASS));
+
+}
+
/*--------------------------------------------------------------------*/
void
_______________________________________________
varnish-dev mailing list
[email protected]
http://lists.varnish-cache.org/mailman/listinfo/varnish-dev