From 59a27de1e0e5d8d7a5aedd67b04ea81fade9063a Mon Sep 17 00:00:00 2001 From: Jens Hassler Date: Fri, 17 Apr 2015 14:38:41 +0200 Subject: [PATCH 1/2] Updated Cookies & Caching section Correct code for Varnish 4 (unset instead of remove) --- cookbook/cache/varnish.rst | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index 054269d6393..c37553420ca 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -76,7 +76,9 @@ session cookie, if there is one, and get rid of all other cookies so that pages are cached if there is no active session. Unless you changed the default configuration of PHP, your session cookie has the name ``PHPSESSID``: -.. code-block:: varnish4 +.. configuration-block:: + + .. code-block:: varnish4 sub vcl_recv { // Remove all cookies except the session ID. @@ -89,11 +91,30 @@ configuration of PHP, your session cookie has the name ``PHPSESSID``: if (req.http.Cookie == "") { // If there are no more cookies, remove the header to get page cached. - remove req.http.Cookie; + unset req.http.Cookie; } } } + .. code-block:: varnish3 + + sub vcl_recv { + // Remove all cookies except the session ID. + if (req.http.Cookie) { + 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 == "") { + // If there are no more cookies, remove the header to get page cached. + remove req.http.Cookie; + } + } + } + + .. tip:: If content is not different for every user, but depends on the roles of a From dd516214f66f7bff12349fe9d6d5ab684b533d88 Mon Sep 17 00:00:00 2001 From: Jens Hassler Date: Mon, 20 Apr 2015 08:41:08 +0200 Subject: [PATCH 2/2] Changed code block indentation --- cookbook/cache/varnish.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index c37553420ca..0e14c3e6be9 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -80,21 +80,21 @@ configuration of PHP, your session cookie has the name ``PHPSESSID``: .. code-block:: varnish4 - sub vcl_recv { - // Remove all cookies except the session ID. - if (req.http.Cookie) { - 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 == "") { - // If there are no more cookies, remove the header to get page cached. - unset req.http.Cookie; + sub vcl_recv { + // Remove all cookies except the session ID. + if (req.http.Cookie) { + 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 == "") { + // If there are no more cookies, remove the header to get page cached. + unset req.http.Cookie; + } } } - } .. code-block:: varnish3