我不确定我问的问题是否正确。我有一个清漆坐在一个可以访问许多cookie的网站前面。最重要的是信条饼干。我正在做的是剥离所有不需要的饼干,然后检查是否留下任何饼干。如果是这样,这意味着我们绕过清漆,否则返回缓存对象。
# Remove all cookies that Drupal doesn't need to know about. We explicitly
# list the ones that Drupal does need, the SESS , NO_CACHE and credential cookie namely auth
#. If, after running this code we find that either of these two cookies remains, we
# will pass as the page cannot be cached.
if (req.http.Cookie) {
# 1. Append a semi-colon to the front of the cookie string.
# 2. Remove all spaces that appear after semi-colons.
# 3. Match the cookies we want to keep, adding the space we removed
# previously back. (1) is first matching group in the regsuball.
# 4. Remove all other cookies, identifying them by the fact that they have
# no space after the preceding semi-colon.
# 5. Remove all spaces and semi-colons from the beginning and end of the
# cookie string.
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]+|SSESS[a-z0-9]+|NO_CACHE+|auth)=", "; 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 is any cookies left (a session or NO_CACHE cookie), do not
# cache the page. Pass it on to Apache directly.
return (pass);
}
}
}
这工作正常。当 cookie 在那里时auth
我会收到缓存未命中,否则就会命中。但是,即使错过了,清漆似乎也会传递请求,而没有请求中的其余cookie。有没有办法引导清漆通过原来的厨师?
也许像
else {
# If there is any cookies left (a session or NO_CACHE cookie), do not
# cache the page. Pass it on to Apache directly.
# And set the cookie to its original form ??
return (pass);
}
您可以在解析之前复制原始cookie,并在语句else
恢复它,如下所示:
# ....
# Store original cookie in other headder
set req.http.X-Cookie = req.http.Cookie;
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]+|SSESS[a-z0-9]+|NO_CACHE+|auth)=", "; 1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
# ....
# Delete cookie copy
unset req.http.X-Cookie;
unset req.http.Cookie;
}
else {
# ...
# Restore original cookie and delete the copy
set req.http.Cookie = req.http.X-Cookie;
unset req.http.X-Cookie;
return (pass);
}
}
}