c - vcl_fetch 中的 if 语句不起作用

标签 c boolean varnish varnish-vcl

仅当 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/

相关文章:

wordpress - 使用 Varnish 代理 WordPress(在 WPEngine 上)

varnish - Varnish 如何处理 HTTP/2 服务器推送?

java - eclipse 中的 JNI :Running the Java code

c - 为什么在 c 中定义的常量末尾使用 'e0'?

python - 如何在 python 中将数字 1 转换为 boolean 值

excel - 将 boolean 自动过滤条件应用于不同的语言

c++ - 无法为参数错误将字符串转换为 'char*'?

c - 如何像在 PHP 中一样使用 c 处理 CGI 中的 session

c - 自 ubuntu 升级以来对 `dlopen' 的 undefined reference

php - 频繁使用网站的缓存策略