Created
May 7, 2014 08:48
-
-
Save zerolab/7a4304f6426ee4b310b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Respond to incoming requests. | |
sub vcl_recv { | |
# ...code from above. | |
# Remove all cookies that Drupal doesn't need to know about. ANY remaining | |
# cookie will cause the request to pass-through to Apache. For the most part | |
# we always set the NO_CACHE cookie after any POST request, disabling the | |
# Varnish cache temporarily. The session cookie allows all authenticated users | |
# to pass through as long as they're logged in. | |
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, ";(SESS[a-z0-9]+|NO_CACHE)=", "; \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 remaining cookies, remove the cookie header. If there | |
# aren't any cookie headers, Varnish's default behavior will be to cache | |
# the page. | |
unset req.http.Cookie; | |
} | |
else { | |
# If there are any cookies left (a session or NO_CACHE cookie), do not | |
# cache the page. Pass it on to Apache directly. | |
return (pass); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Via https://www.lullabot.com/blog/article/configuring-varnish-high-availability-multiple-web-servers
The cookie snippet removes all spaces from cookies, then adds them for allowed cookies, then removes all cookies having no space before the ; and removes any prefixed cookies. So instead of whitelisting cookies, it is removing all besides SESS* and NO_CACHE cookies.