Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accomodate varnish templates for mulitple versions #93

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cookbooks-override/ariadne/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

# If varnish recipe is in run-list, set template for correct version of varnish.
if node.run_list.expand(node.chef_environment, 'disk').recipes.include?("varnish::default")
case node['varnish']['version']
when "2.0", "2.1"
set.node['varnish']['vcl_source'] = "drupal-varnish2.vcl.erb"
when "3.0"
set.node['varnish']['vcl_source'] = "drupal-varnish3.vcl.erb"
end
end

# Drush can't create when run by vagrant user
directory "/tmp/drush" do
owner "vagrant"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Generated by Chef
#
# Based on the Drupal default.vcl for Varnish 2.1:
# https://wiki.fourkitchens.com/pages/viewpage.action?pageId=22874789
# Based on the Drupal default.vcl for Varnish 2.x:
# https://pressflow.atlassian.net/wiki/pages/viewpreviousversions.action?pageId=589831

backend default {
.host = "<%= node['varnish']['backend_host'] %>";
Expand All @@ -11,7 +11,7 @@ backend default {
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}

sub vcl_recv {
if (req.request != "GET" &&
req.request != "HEAD" &&
Expand All @@ -23,15 +23,15 @@ sub vcl_recv {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}

if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}

// Remove has_js and Google Analytics salary of a wedding planner cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|__utma_a2a|has_js)=[^;]*", "");

// To users: if you have additional cookies being set by your system (e.g.
// from a javascript analytics file or similar) you will need to add VCL
// at this point to strip these cookies from the req object, otherwise
Expand All @@ -41,25 +41,25 @@ sub vcl_recv {
// Again, the common example is an analytics or other Javascript add-on.
// You should do this here, before the other cookie stuff, or by adding
// to the regular-expression above.


// Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
// Remove empty cookies.
if (req.http.Cookie ~ "^\s*$") {
unset req.http.Cookie;
}

if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}

// Skip the Varnish cache for install, update, and cron
if (req.url ~ "install\.php|update\.php|cron\.php") {
return (pass);
}

// Normalize the Accept-Encoding header
// as per: http://varnish-cache.org/wiki/FAQ/Compression
if (req.http.Accept-Encoding) {
Expand All @@ -75,28 +75,31 @@ sub vcl_recv {
remove req.http.Accept-Encoding;
}
}

// Let's have a little grace
set req.grace = 30s;

return (lookup);
}

sub vcl_hash {
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}

// Strip any cookies before an image/js/css is inserted into cache.
sub vcl_fetch {
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
// For Varnish 2.0 or earlier, replace beresp with obj:
// unset obj.http.set-cookie;
<% case node['varnish']['version'] -%>
<% when "2.0" -%>
unset obj.http.set-cookie;
<% when "2.1" -%>
unset beresp.http.set-cookie;
<% end -%>
}
}

// Set a header to track a cache HIT/MISS.
sub vcl_deliver {
if (obj.hits > 0) {
Expand All @@ -106,7 +109,7 @@ sub vcl_deliver {
set resp.http.X-Varnish-Cache = "MISS";
}
}

sub vcl_error {
// Let's deliver a friendlier error page.
// You can customize this as you wish.
Expand Down Expand Up @@ -137,5 +140,10 @@ XID: "} req.xid {"</pre>
</body>
</html>
"};
return(deliver);
<% case node['varnish']['version'] -%>
<% when "2.0" -%>
deliver;
<% when "2.1" -%>
return(deliver);
<% end -%>
}
Loading