Skip to content

Commit 1d6830f

Browse files
committed
minor #5188 Updated Cookies & Caching section (lukey78)
This PR was submitted for the 2.6 branch but it was merged into the 2.3 branch instead (closes #5188). Discussion ---------- Updated Cookies & Caching section Correct code for Varnish 4 (unset instead of remove) Commits ------- 805a548 Updated Cookies & Caching section
2 parents a8d4cea + 805a548 commit 1d6830f

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

cookbook/cache/varnish.rst

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,44 @@ session cookie, if there is one, and get rid of all other cookies so that pages
7575
are cached if there is no active session. Unless you changed the default
7676
configuration of PHP, your session cookie has the name ``PHPSESSID``:
7777

78-
.. code-block:: varnish4
78+
.. configuration-block::
7979

80-
sub vcl_recv {
81-
// Remove all cookies except the session ID.
82-
if (req.http.Cookie) {
83-
set req.http.Cookie = ";" + req.http.Cookie;
84-
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
85-
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
86-
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
87-
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
88-
89-
if (req.http.Cookie == "") {
90-
// If there are no more cookies, remove the header to get page cached.
91-
remove req.http.Cookie;
80+
.. code-block:: varnish4
81+
82+
sub vcl_recv {
83+
// Remove all cookies except the session ID.
84+
if (req.http.Cookie) {
85+
set req.http.Cookie = ";" + req.http.Cookie;
86+
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
87+
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
88+
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
89+
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
90+
91+
if (req.http.Cookie == "") {
92+
// If there are no more cookies, remove the header to get page cached.
93+
unset req.http.Cookie;
94+
}
9295
}
9396
}
94-
}
97+
98+
.. code-block:: varnish3
99+
100+
sub vcl_recv {
101+
// Remove all cookies except the session ID.
102+
if (req.http.Cookie) {
103+
set req.http.Cookie = ";" + req.http.Cookie;
104+
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
105+
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
106+
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
107+
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
108+
109+
if (req.http.Cookie == "") {
110+
// If there are no more cookies, remove the header to get page cached.
111+
remove req.http.Cookie;
112+
}
113+
}
114+
}
115+
95116
96117
.. tip::
97118

0 commit comments

Comments
 (0)