【问题标题】:If statement in vcl_fetch not working如果 vcl_fetch 中的语句不起作用
【发布时间】:2014-06-28 20:38:53
【问题描述】:

仅当 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 响应标头为“非演示安全”。但是取消注释错误 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”标题,不确定这是怎么可能的,因为在取消注释错误 200 行时,相同的 url 给了我“/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

【问题讨论】:

    标签: c boolean varnish varnish-vcl


    【解决方案1】:

    我在 firebug/chrome 开发工具中查看了错误的请求。我正在检查的请求是对 mysite.com/app_dev.php/_wdt/60c03d 发出的 xhr 请求,并且没有 /demo/secured ,所以它有正确的标题。

    现在是时候离开电脑了,明天继续。

    【讨论】:

      猜你喜欢
      • 2012-12-26
      • 2013-06-20
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多