2016-10-11 99 views
0

我想在VCL中设置Cookie时指定过期日期。目前,我有这样的事情:设置Cookie时的过期日期

add resp.http.Set-Cookie = "language=" + req.http.X-Language + "; path=/"; 

我知道,我必须添加这样的事情:

Expires=Thu, 01 Jan 1970 00:00:00 GMT 

是否有清漆一个内置的功能,让我来动态设置到期日期到将来的任何事情?我一直在看他们的文档,但目前为止没有运气。

非常感谢您提前。

-Angel

回答

2

更新 - 工作的解决方案:如果

不知道这句法是针对快速度,但我得到它的工作使用:time.add(now,1d)

add resp.http.Set-Cookie = "language=" + req.http.X-Language + ";expires="+ time.add(now,1d) +"; path=/"; 
+0

看样子成为语法的一大部分。 – Danack

0

如果使用Varnish 4,则应使用Cookie VMOD。 从DOC: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"; 
}