简体   繁体   English

如何在ESI中设置cookie:include脚本?

[英]How do you set a cookie from within an ESI:include script?

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. 我有一个基本的PHP页面通过Varnish加载,其中包含一个ESI回调服务器来设置cookie。 The cookie is set with domain access and the like, but when called through ESI the cookie is never set. cookie是通过域访问等设置的,但是当通过ESI调用时,cookie永远不会被设置。 If you access the ESI include path directly, the cookie is set with no issue. 如果直接访问ESI包含路径,则cookie设置没有问题。 I have even set my Varnish configuration to never cache anything, thinking the VCL could be killing the cookie. 我甚至设置了我的Varnish配置永远不会缓存任何东西,认为VCL可能会杀死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. 我是Varnish和ESI的新手,所以我开始怀疑这是否是一个已知的限制(使用ESI或使用Varnish的ESI实现),但我在网上找不到任何关于我的问题的讨论。

An interesting question which has been asked -but not answered- before ( Setting Cookies via ESI:include, how? ). 一个有趣的问题,但之前没有回答过( 通过ESI设置Cookies:包括,如何? )。 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. 使用ESI-include,ESI处理器会发出单独的请求,并从主体而不是标头中替换部件。 In order to make your preferred set-cookie behavior work correctly, the ESI specification should specify how to 'merge' all set-cookie headers. 为了使您首选的set-cookie行为正常工作,ESI规范应指定如何“合并”所有set-cookie标头。

See chapter six of the ESI spec: http://www.w3.org/TR/esi-lang 参见ESI规范的第六章: http//www.w3.org/TR/esi-lang

When an ESI template is processed, a separate request will need to be made for each include encountered. 处理ESI模板时,需要为遇到的每个包含单独的请求。 Implementations may use the original request's headers (eg, Cookie, User-Agent, etc.) when doing so. 在执行此操作时,实现可以使用原始请求的标头(例如,Cookie,用户代理等)。 Additionally, response headers from fragments (eg, Set-Cookie, Server, Cache-Control, Last-Modified) may be ignored, and should not influence the assembled page. 另外,可以忽略来自片段的响应头(例如,Set-Cookie,Server,Cache-Control,Last-Modified),并且不应该影响组装的页面。

Could you try to convert your set-cookie header in a javascript set-cookie script? 你能尝试在javascript set-cookie脚本中转换你的set-cookie标头吗? This could be included in the body... 这可以包括在身体里......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM