Skip to content

Commit 92c4f11

Browse files
author
Jeroen Vermeulen
committed
Applied PR nexcess#1415 to the feature to allow reuse of ESI blocks for new visitors.
Varnish 4 only yet.
1 parent 54eb503 commit 92c4f11

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,11 @@ protected function _vcl_sub_set_cookie_domain()
10461046
}
10471047
$count = 0;
10481048
foreach ($domain2cookie as $domain => $cookieDomain) {
1049-
$if = ($count == 0) ? ' if' : ' elsif';
1049+
$if = ($count == 0) ? ' if' : ' elsif';
10501050
$tpl .= <<<EOS
10511051
$if (resp.http.X-Varnish-CookieDomain == "$domain") {
1052-
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
1053-
}
1052+
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
1053+
}
10541054
EOS;
10551055
$count++;
10561056
}

app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,28 +428,25 @@ sub vcl_deliver {
428428
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
429429
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
430430
if (req.http.Host) {
431+
if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") {
432+
set resp.http.X-Varnish-CookieDomain = "{{normalize_cookie_target}}";
433+
} else {
434+
set resp.http.X-Varnish-CookieDomain = regsub(req.http.Host, ":\d+$", "");
435+
{{set_cookie_domain}}
436+
}
431437
if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") {
432438
# it's a crawler, no need to share cookies
433439
set resp.http.Set-Cookie = resp.http.Set-Cookie +
434440
"; domain=" + regsub(req.http.Host, ":\d+$", "");
435441
} else {
436442
# it's a real user, allow sharing of cookies between stores
437-
if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") {
438-
set resp.http.Set-Cookie = resp.http.Set-Cookie +
439-
"; domain={{normalize_cookie_target}}";
440-
} else {
441-
set resp.http.X-Varnish-CookieDomain = regsub(req.http.Host, ":\d+$", "");
442-
{{set_cookie_domain}}
443-
set resp.http.Set-Cookie = resp.http.Set-Cookie +
444-
"; domain=" + resp.http.X-Varnish-CookieDomain;
445-
}
443+
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain=" + resp.http.X-Varnish-CookieDomain;
446444
}
447445
}
448446
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
449-
if ({{reuse_new_visitor_esi_blocks}}) {
450-
# @TODO Apply CookieDomain fixes
447+
if ({{reuse_new_visitor_esi_blocks}} && resp.http.X-Varnish-CookieDomain) {
451448
header.append( resp.http.Set-Cookie, "turpentine_new=1; expires=" + resp.http.X-Varnish-Cookie-Expires +
452-
"; path=/; domain=" + req.http.Host + "; httponly" );
449+
"; path=/; domain=" + resp.http.X-Varnish-CookieDomain + "; httponly" );
453450
}
454451
unset resp.http.X-Varnish-Cookie-Expires;
455452
}

0 commit comments

Comments
 (0)