如何在 ESI:include 脚本中设置 cookie?
我有一个通过 Varnish 加载的基本 PHP 页面,其中包含一个 ESI 包含回调到服务器以设置 cookie。 cookie 是通过域访问等设置的,但是当通过 ESI 调用时,永远不会设置 cookie。如果直接访问 ESI 包含路径,则设置 cookie 不会出现问题。我什至将 Varnish 配置设置为从不缓存任何内容,认为 VCL 可能会杀死 cookie。
这...
<esi:include src="/init.php?<?=http_build_query($_GET); ?>"></esi:include>
...包括这个...
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
setcookie('superman', 'clark kent', 0, '/', '.whatever.com');
?>
我是 Varnish 和 ESI 的新手,所以我开始怀疑这是否是一个已知的限制(无论是使用 ESI 还是使用 Varnish 的 ESI 实现),但我不能在线查找有关我的问题的任何讨论。
I have a basic PHP page being loaded through Varnish with a single ESI include that calls back to the server to set a cookie. The cookie is set with domain access and the like, but when called through ESI the cookie is never set. If you access the ESI include path directly, the cookie is set with no issue. I have even set my Varnish configuration to never cache anything, thinking the VCL could be killing the cookie.
This...
<esi:include src="/init.php?<?=http_build_query($_GET); ?>"></esi:include>
...includes this...
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
setcookie('superman', 'clark kent', 0, '/', '.whatever.com');
?>
I'm new with Varnish and ESI, so I'm starting to wonder if this is a known limitation (either with ESI or with Varnish's ESI implementation), but I can't find any discussion of my problem online.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个有趣的问题,之前已经被问过,但没有得到解答(通过 ESI:include 设置 Cookie,如何?)。我认为你不能这样做。通过 ESI-include,ESI 处理器发出单独的请求并替换正文中的一部分,而不是标头。为了使您首选的 set-cookie 行为正常工作,ESI 规范应指定如何“合并”所有 set-cookie 标头。
请参阅 ESI 规范第六章:http://www.w3.org/TR/esi-语言
您可以尝试在 javascript set-cookie 脚本中转换您的 set-cookie 标头吗?这可以包含在正文中......
An interesting question which has been asked -but not answered- before ( Setting Cookies via ESI:include, how? ). I don't think you can do it this way. With ESI-include, the ESI processor makes a separate request and replaces a part from the body, not the header. In order to make your preferred set-cookie behavior work correctly, the ESI specification should specify how to 'merge' all set-cookie headers.
See chapter six of the ESI spec: http://www.w3.org/TR/esi-lang
Could you try to convert your set-cookie header in a javascript set-cookie script? This could be included in the body...