Skip to content

Commit 68ecba8

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 185125d commit 68ecba8

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
@@ -1032,11 +1032,11 @@ protected function _vcl_sub_set_cookie_domain()
10321032
}
10331033
$count = 0;
10341034
foreach ($domain2cookie as $domain => $cookieDomain) {
1035-
$if = ($count == 0) ? ' if' : ' elsif';
1035+
$if = ($count == 0) ? ' if' : ' elsif';
10361036
$tpl .= <<<EOS
10371037
$if (resp.http.X-Varnish-CookieDomain == "$domain") {
1038-
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
1039-
}
1038+
set resp.http.X-Varnish-CookieDomain = "$cookieDomain";
1039+
}
10401040
EOS;
10411041
$count++;
10421042
}

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

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

0 commit comments

Comments
 (0)