0

I want a rule in my vcl_recv that checks if a certain cookie is present, and if so always serves a cached file (let's call this cookie VARNISH_USE_CACHE)

However, I also have a rule that runs after this to check for a session cookie (and if it exists always passes to apache), this rule should still run if VARNISH_USE_CACHE is not present.

I'm not quite sure how to check for one cookie and then check for another. I've tried assigning the cookies to a temp variable, and checking there. But I must not be understanding how vcl works, as when I do this I end up with the full cookie with nothing stripped out.

Here's my code in vcl_rec:

set req.http.tempCookie = ";" + req.http.Cookie;
set req.http.tempCookie = regsuball(req.http.tempCookie, ";(VARNISH_USE_CACHE)=", "; \1=");
set req.http.tempCookie = regsuball(req.http.tempCookie, ";[^ ][^;]*", "");
set req.http.tempCookie = regsuball(req.http.tempCookie, "^[; ]+|[; ]+$", "");

So I'm expecting req.http.tempCookie to be empty if there is no VARNISH_USE_CACHE, instead it always has all the cookies from req.http.Cookie.

leon.nk
  • 437
  • 2
  • 6
  • 15

1 Answers1

0

Ah worked it out:

Forgot this line

set req.http.tempCookie = regsuball(req.http.tempCookie, "; +", ";");

So the code looks like:

set req.http.tempCookie = ";" + req.http.Cookie;
set req.http.tempCookie = regsuball(req.http.tempCookie, "; +", ";");
set req.http.tempCookie = regsuball(req.http.tempCookie, ";(VARNISH_USE_CACHE)=", "; \1=");
set req.http.tempCookie = regsuball(req.http.tempCookie, ";[^ ][^;]*", "");
set req.http.tempCookie = regsuball(req.http.tempCookie, "^[; ]+|[; ]+$", "");
leon.nk
  • 437
  • 2
  • 6
  • 15