PHP Benelux, January 28th, 2017
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-3600);
}
sub vcl_recv {
set req.http.cookie = ";" + req.http.cookie;
set req.http.cookie = regsuball(req.http.cookie, "; +", ";");
set req.http.cookie = regsuball(req.http.cookie, ";(PHPSESSID)=", "; \1=");
set req.http.cookie = regsuball(req.http.cookie, ";[^ ][^;]*", "");
set req.http.cookie = regsuball(req.http.cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
remove req.http.Cookie;
}
}
varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies #RemovingallBUTsomecookies
$(document).ready(function () {
$("#labels-edit").show();
$("#milestone-edit").show();
$("#assignee-edit").show();
});
$(document).ready(function () {
$.ajax({
url: "/sidebar.html"
}).done(function( html ) {
$( "#sidebar" ).append( html );
});
});
Cache-Control: no-cache
Vary: Cookie
Cache-Control: public, s-maxage: ...
// builtin.vcl
sub vcl_recv {
// ...
if (req.method != "GET" && req.method != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (hash);
}
// default.vcl
sub vcl_recv {
// ...
if (req.method != "GET" && req.method != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
return (hash);
}
<html>
<body>
Main body.
<esi:include src="fragment.php" />
</body>
</html>
sub vcl_recv {
// Add a Surrogate-Capability header
// to announce ESI support.
set req.http.Surrogate-Capability = "abc=ESI/1.0";
}
sub vcl_backend_response {
// Check for ESI acknowledgement
// and remove Surrogate-Control header.
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
}
# app/config/config.yml
framework:
esi: { enabled: true }
fragments: { path: /_fragment }
Make sure either your webserver is only reachable from the Varnish server or add access restrictions for /_fragment
{# index.html.twig #}
{% render_esi(controller( 'AppBundle:Comments:comments', {'param': 42 })) %}