diff --git a/docs/default_3.0.vcl b/docs/default_3.0.vcl new file mode 100644 index 0000000..61902bd --- /dev/null +++ b/docs/default_3.0.vcl @@ -0,0 +1,35 @@ +#-e This is a basic VCL configuration file for varnish. See the vcl(7) +#man page for details on VCL syntax and semantics. +# + + +# load the ESI-blocks VCL +# This should be in the same folder, or given an absolute path to the VCL. +include "esi_blocks.vcl"; + + +backend default { + .host = "127.0.0.1"; + .port = "8080"; +} + + + +sub vcl_recv { + call esi_block__recv; +} + +sub vcl_hash { + call esi_block__hash; +} + +sub vcl_fetch { + # don't ESI anything with a 3/4 letter extension + # (e.g. don't try to ESI images, css, etc). + if (! req.url ~ "\..{3,4}$") { + set beresp.do_esi = true + esi; + } + + call esi_block__fetch; +} diff --git a/docs/esi_blocks.vcl b/docs/esi_blocks.vcl index 4105190..57e294d 100644 --- a/docs/esi_blocks.vcl +++ b/docs/esi_blocks.vcl @@ -43,7 +43,7 @@ sub esi_block__recv { # The URL structure of ESI blocks identifies which are per-user or per-role. # e.g. /esi/block/garland:left:foo:bar/node%2F1/CACHE=USER # Add a header to show if we're using a particular cache strategy. - if( req.url ~ "^/esi/block" ) { + if ((req.url ~ "^/esi/block" ) || (req.url ~ "^/esi/panels_pane" )) { # look for a cache instruction. This should be the final argument to the URL # and should have the value 'USER' or 'ROLE'. diff --git a/docs/esi_blocks_3.0.vcl b/docs/esi_blocks_3.0.vcl new file mode 100644 index 0000000..88f2bcb --- /dev/null +++ b/docs/esi_blocks_3.0.vcl @@ -0,0 +1,101 @@ + +### +# Custom subroutines to provide ESI support for Drupal blocks with the +# Drupal ESI module. +## + +/** + * Alter the hash per-user or per-role + */ +sub esi_block__hash { + # Customise the hash if required. + if ( req.http.X_BLOCK_CACHE ) { + if( req.http.X_BLOCK_CACHE == "USER" ) { + if( req.http.Cookie ~ "SESS" ) { + # This pulls the session-name and session-id from the cookie string. + set req.http.X-SESSION-ID = + regsub( req.http.Cookie, "^.*?SESS(.{32})=([^;]*);*.*$", "\1\2" ); + + # add the session info to the hash. + + # 3.0 + hash_data(req.http.X-SESSION-ID); + # 2.x + #set req.hash += req.http.X-SESSION-ID; + } + } + + if( req.http.X_BLOCK_CACHE == "ROLE" ) { + # Roles are identified by a cookie beginning RSESS + if( req.http.Cookie ~ "RSESS" ) { + # This pulls the role info from the cookie string. + set req.http.X-ROLE-SESSION-ID = + regsub( req.http.Cookie, "^.*?RSESS(.{32})=([^;]*);*.*$", "\1\2" ); + + # add the session info to the hash. + + # 3.0 + hash_data(req.http.X-ROLE-SESSION-ID); + # 2.x + #set req.hash += req.http.X-ROLE-SESSION-ID; + } + } + } +} + + +/** + * Add an http header if an ESI block has per-user or per-role cache rules + */ +sub esi_block__recv { + + # The URL structure of ESI blocks identifies which are per-user or per-role. + # e.g. /esi/block/garland:left:foo:bar/node%2F1/CACHE=USER + # Add a header to show if we're using a particular cache strategy. + if ((req.url ~ "^/esi/block" ) || (req.url ~ "^/esi/panels_pane" )) { + + # look for a cache instruction. This should be the final argument to the URL + # and should have the value 'USER' or 'ROLE'. + if ( req.url ~ "^.*/CACHE=[^/]*$" ) { + + # Set an HTTP_X_BLOCK_CACHE header to be appropriate setting. + set req.http.X_BLOCK_CACHE = + regsub( req.url, "^.*/CACHE=([^/]*)$", "\1" ); + + # Strip the cache-instruction from the end of the URL. + set req.url = + regsub( req.url, "^(.*)/CACHE=[^/]*$", "\1" ); + } + } + + # Ignore presence of cookies, etc, for ESI requests: + # Always try to lookup ESIs from the cache. + if(req.url ~ "^/esi.*") { + # 3.0 + return (lookup); + # 2.x + #lookup; + } +} + + +/** + * Cache ESI'd block content. + */ +sub esi_block__fetch { + # ESI blocks with per-user or per-role config have a cache-control: private + # header. This removes the header and inserts the block into the cache. + + # 3.0 + if( beresp.http.Cache-Control ~ "private" ) { + unset beresp.http.Set-Cookie; + unset beresp.http.Cache-Control; + return (deliver); + } + # 2.x + #if( obj.http.Cache-Control ~ "private" ) { + # unset obj.http.Set-Cookie; + # unset obj.http.Cache-Control; + # deliver; + #} +}