Skip to content

Commit

Permalink
Applied PR nexcess#1415 to the feature to allow reuse of ESI blocks f…
Browse files Browse the repository at this point in the history
…or new visitors.

Varnish 4 only yet.
  • Loading branch information
Jeroen Vermeulen committed Jun 22, 2017
1 parent 54eb503 commit 92c4f11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,11 @@ protected function _vcl_sub_set_cookie_domain()
}
$count = 0;
foreach ($domain2cookie as $domain => $cookieDomain) {
$if = ($count == 0) ? ' if' : ' elsif';
$if = ($count == 0) ? ' if' : ' elsif';
$tpl .= <<<EOS
$if (resp.http.X-Varnish-CookieDomain == "$domain") {
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
}
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
}
EOS;
$count++;
}
Expand Down
21 changes: 9 additions & 12 deletions app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -428,28 +428,25 @@ sub vcl_deliver {
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") {
set resp.http.X-Varnish-CookieDomain = "{{normalize_cookie_target}}";
} else {
set resp.http.X-Varnish-CookieDomain = regsub(req.http.Host, ":\d+$", "");
{{set_cookie_domain}}
}
if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") {
# it's a crawler, no need to share cookies
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":\d+$", "");
} else {
# it's a real user, allow sharing of cookies between stores
if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain={{normalize_cookie_target}}";
} else {
set resp.http.X-Varnish-CookieDomain = regsub(req.http.Host, ":\d+$", "");
{{set_cookie_domain}}
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + resp.http.X-Varnish-CookieDomain;
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain=" + resp.http.X-Varnish-CookieDomain;
}
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
if ({{reuse_new_visitor_esi_blocks}}) {
# @TODO Apply CookieDomain fixes
if ({{reuse_new_visitor_esi_blocks}} && resp.http.X-Varnish-CookieDomain) {
header.append( resp.http.Set-Cookie, "turpentine_new=1; expires=" + resp.http.X-Varnish-Cookie-Expires +
"; path=/; domain=" + req.http.Host + "; httponly" );
"; path=/; domain=" + resp.http.X-Varnish-CookieDomain + "; httponly" );
}
unset resp.http.X-Varnish-Cookie-Expires;
}
Expand Down

0 comments on commit 92c4f11

Please sign in to comment.