The problem with the code above is this line in the default.vcl that gets called later on:
if (req.http.Authorization || req.http.Cookie) {
# /* Not cacheable by default */
return (pass);
}
It is commented out, but still gets called as part of the default behavior of Varnish. As you can see, it is asking if
req.http.Cookie
exists. In the code provided in the question, the variable will still exist, but will be an empty string. This empty string will still pass the logical test in the default Varnish behavior. As a result, the following code must be added after the code which removes the undesirable cookies:
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_\.a-z0-9]+|has_js)=[^;]*", "");
# //Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s", "");
if (req.http.Cookie == "") {
unset req.http.Cookie;
}
Now, if the req.http.Cookie is empty, the object will be removed and Varnish will cache as expected.