因此,如何(未經測試):
# We use builtin.vcl logic and 'return' from our vcl_recv in order
# to prevent default Varnish behaviour of not caching with cookies present
sub vcl_recv {
# your vcl_recv starts here
# ...
# your vcl_recv ends here
if (req.method == "PRI") {
/* We do not support SPDY or HTTP/2.0 */
return (synth(405));
}
if (req.method != "GET" &&
req.method != "HEAD" &&
req.method != "PUT" &&
req.method != "POST" &&
req.method != "TRACE" &&
req.method != "OPTIONS" &&
req.method != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.method != "GET" && req.method != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization) {
/* Not cacheable by default */
return (pass);
}
return (hash);
}
sub vcl_hash {
set req.http.X-Cookie-Hash = regsub(req.http.cookie, "KNOWN1=[^;]+;", "");
set req.http.X-Cookie-Hash = regsub(req.http.X-Cookie-Hash, "KNOWN2=[^;]+;", "");
hash_data(req.http.X-Cookie-Hash);
}
從而消除各知名餅乾和散列在餘:)不理想,因爲它不能保證在頭的cookie的順序,而是從其他這應該工作。
只是爲了確認,你想散列一些UNKNOWN cookie(不包括那些已知的cookies)? –
是的,通常的哈希組件(主機,url)必須保留爲哈希的一部分。 – hedleyroos