仅当 url 不像“demo/secured”时才尝试删除 cookie
在default.vcl中我有:
sub vcl_fetch {
# error 200 req.url ~ ".*/demo/secured/.*";
if (req.url ~ ".*/demo/secured/.*") {
set beresp.http.x-whaaat = "this is demo securd";
}else {
unset beresp.http.set-cookie;
set beresp.http.x-whaaat = "not demo secured";
}
}
带或不带/demo/secured 的两个 url 都会导致 x-whaaat 响应 header “not demo secure”。但是,取消注释错误 200 行会为带有 demo/secured 的 url 提供错误 200 true,为没有 demo/secured 的 url 提供错误 200 false。
我尝试了无数种 if 语句的变体,但无法让它返回除 false 之外的任何内容。
下列说法正确的是:
if ( "/app_dev.php/demo/secured/login" ~ ".*/demo/secured/.*" )
尽管我从 error 200 req.url
的页面输出中复制并粘贴了“/app_dev.php/demo/secured/login”,但以下内容并不正确:
# error 200 req.url;
if ( req.url ~ ".*/demo/secured/.*" ) {
set beresp.http.x-whaaat = "this is demo securd";
}else {
unset beresp.http.set-cookie;
set beresp.http.x-whaaat = "not demo secured";
}
在 http://site/app_dev.php/demo/secured/login
上给了我一个“x-whaat not demo secure” header ,不知道这是如何可能的,因为相同的网址给了我取消注释错误 200 行时的“/app_dev.php/demo/secured/login”。
varnishd -V
给我:
varnishd (varnish-3.0.5 revision 1a89b1f)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
最佳答案
我在 firebug/chrome 开发工具中查看了错误的请求。我正在检查的请求是向 mysite.com/app_dev.php/_wdt/60c03d 发出的 xhr 请求,并且没有/demo/secured,因此肯定它具有正确的 header 。
现在是时候离开电脑一段时间了,明天继续。
关于c - vcl_fetch 中的 if 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23592848/