@@ -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