每个请求在Varnish中传递变量

时间:2016-09-28 16:38:30

标签: varnish

如何跨子例程传递变量?

我有以下default.vcl:

vcl 4.0;

sub vcl_recv {
     set req.http.x-tracking-first-request = "true";
}


sub vcl_deliver {

    if (resp.http.x-tracking-first-request) { 
       # do something
    }
}

目前我必须在后端处理参数,例如response.add_header("x-tracking-first-request", response.get_header("x-tracking-first-request"))。这意味着每个客户端必须实现这个"反射"逻辑。

为什么呢? Uppon第一次请求我想生成一个uuid以便以后识别不同的用户。因此,我必须以某种方式在所有请求/响应周期中保存uuid。

1 个答案:

答案 0 :(得分:1)

您只需在req期间使用vcl_deliver对象:

vcl 4.0;

sub vcl_recv {
     set req.http.x-tracking-first-request = "true";
}

sub vcl_deliver {
    if (req.http.x-tracking-first-request) { 
       # do something
    }
}
相关问题