[Varnish] #411: restart not available in vcl_deliver
Varnish
varnish-bugs at projects.linpro.no
Wed Dec 17 13:31:04 CET 2008
#411: restart not available in vcl_deliver
----------------------+-----------------------------------------------------
Reporter: hajile | Owner: phk
Type: defect | Status: new
Priority: normal | Milestone:
Component: varnishd | Version: trunk
Severity: normal | Keywords:
----------------------+-----------------------------------------------------
Reason for restart in vcl_deliver (not in fetch or hit) is to cache a
redirect (in my case 303: See other) in fetch phase, then restart with
url=Location right in varnish, without redirecting the client (thus
optimizing internal network traffic).
Both operations are perfectly cacheable and at the same time consistent
(no need to purge two urls, purge only the primary one).
This feature is very useful for proxying RESTful services:
/object/{id} -> return document [cached, purge when return document
changes]
/object/?findByNonPrimaryButUniqueKey=bla -> HTTP 303 ( /object/{id} )
[cached, purge only when this unique key changes]
/object/?findByOtherNonPrimaryButUniqueKey=22895723658 -> HTTP 303 (
/object/{id} ) [cached, -""-]
sub vcl_hit {
if (obj.http.X-Magic-Redirect == "1") {
set req.url = obj.http.Location;
restart;
}
}
sub vcl_fetch {
if (obj.status == 301 || obj.status == 302 || obj.status == 303 ||
obj.status == 307) {
if (obj.status == 303) {
set obj.http.X-Magic-Redirect = "1";
}
deliver;
}
}
sub vcl_deliver {
if (resp.http.X-Magic-Redirect == "1") {
unset resp.http.X-Magic-Redirect;
restart;
}
deliver;
}
--
Ticket URL: <http://varnish.projects.linpro.no/ticket/411>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator
More information about the varnish-bugs
mailing list