我想在我的vcl_recv中使用一条规则来检查某个cookie是否存在,如果是,则始终提供缓存文件(让我们将此cookie称为VARNISH_USE_CACHE)
但是,我还有一个规则在此之后运行以检查会话cookie(如果它存在总是传递给apache),如果VARNISH_USE_CACHE不存在,该规则仍然应该运行。
我不太确定如何检查一个cookie,然后检查另一个。我已经尝试将cookie分配给临时变量,并检查那里。但是我不能理解vcl是如何工作的,因为当我这样做时,我最终得到了完整的cookie而没有被删除。
这是我在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, "^[; ]+|[; ]+$", "");
所以如果没有VARNISH_USE_CACHE,我希望req.http.tempCookie为空,而是总是拥有req.http.Cookie的所有cookie。
答案 0 :(得分:0)
啊解决了问题:
忘记了这一行
set req.http.tempCookie = regsuball(req.http.tempCookie, "; +", ";");
所以代码如下:
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, "^[; ]+|[; ]+$", "");