我想在VCL中设置Cookie时指定到期日期。我现在有这样的事情:
add resp.http.Set-Cookie = "language=" + req.http.X-Language + "; path=/";
我知道我必须添加这样的东西:
Expires=Thu, 01 Jan 1970 00:00:00 GMT
Varnish中是否有内置函数允许我将过期日期动态设置为将来的任何内容?我一直在看他们的文档,但到目前为止没有运气。
非常感谢你。
-Angel
答案 0 :(得分:2)
更新 - 工作解决方案:
不确定此语法是否特定于Fastly,但我使用了time.add(now,1d)
:
add resp.http.Set-Cookie = "language=" + req.http.X-Language + ";expires="+ time.add(now,1d) +"; path=/";
答案 1 :(得分:0)
如果您使用Varnish 4,则应使用Cookie VMOD。 来自文档:https://github.com/varnish/varnish-modules/blob/master/docs/vmod_cookie.rst
format_rfc1123 STRING format_rfc1123(TIME now, DURATION timedelta) Description Get a RFC1123 formatted date string suitable for inclusion in a Set-Cookie response header. Care should be taken if the response has multiple Set-Cookie headers. In that case the header vmod should be used. Example sub vcl_deliver { # Set a userid cookie on the client that lives for 5 minutes. set resp.http.Set-Cookie = "userid=" + req.http.userid + "; Expires=" + cookie.format_rfc1123(now, 5m) + "; httpOnly"; }