Set-Cookie header 在 Glassfish-5 中:将多个 cookie 合二为一 header 在 Firefox 上不工作 (https + HTTP/2.0)

Set-Cookie header in Glassfish-5: folding several cookies in one header not working on Firefox (https + HTTP/2.0)

我注意到 Glassfish-5 网络服务器发送的响应只有一个 Set-Cookie header,其中包含多个 cookie。当我查看 firebug 时,我可以看到它们由未知字符分隔。无论如何 - Firefox 只读取第一个 cookie。如何配置 Glassfish5 发送多个 Set-Cookie headers - 每个 cookie 一个? rfc6265 指出:

  1. Overview
    ...
    Origin servers SHOULD NOT fold multiple Set-Cookie header fields into a single header field. The usual mechanism for folding HTTP headers fields (i.e., as defined in [RFC2616]) might change the semantics of the Set-Cookie header field because the %x2C (",") character is used by Set-Cookie in a way that conflicts with such folding.
    ...

还有here说:

When sending an HTTP Response with multiple cookies, CFHTTPMessage combines the cookies into a comma-separated list under a single "Set-Cookie" HTTP header. (This is referred to as "set-cookie-folding".)

Set-cookie-folding is NOT supported on Google Chrome, Firefox, and Internet Explorer. Each of those browsers will completely ignore every cookie after the first comma, rendering CFHTTPMessage completely useless for handling HTTP responses with multiple cookies in any browser other than Safari (which supports cookie-folding).

这是 firebug 上的响应: 两个 cookie 由未知字符连接。正如我注意到的那样 - 其他服务器(如 Apache)通过换行符将多个 cookie 拆分为一个 Set-Cookie header。

我注意到这只发生在 HTTPS 连接上。

此外,我已经在 Github here 上打开了一个问题。

在 Tomcat 9 网络服务器上尝试了与 运行 相同的网络应用程序 - Set-Cookie header cookie 由换行符分隔,它按预期工作。 .

相同的响应,但在 Glassfish5 上,并且再次 - cookie 由未知字符连接,并且不被 Firefox 接受(只是第一个):

在 NetBeans IDE 8.2 HTTP 服务器监视器中我可以看到,发送了 2 个 cookie - 看起来没问题:

再一次在 FireFox 上 - 2 个 cookie 合二为一 Set-Cookie header:

只收到一个 - 值不正确...:

Firefox Developer Edition 相同:

一头雾水..

Glassfish 5 使用 Grizzly Framework 2.4.0 - 我认为源代码在 grizzly-http-servlet-2.4.0-sources.jar 中可用 - 但找不到将 cookie 连成一行的代码片段..

我现在可以确认它仅与 HTTP/2.0 协议相关,由 enabling/disabling network.http.spdy.enabled.http2about:config 中在 firefox 上测试。在 HTTP/1.1 上,通过 HTTPS cookie 按预期设置。

在我们删除的一系列评论中,我指出奇怪的响应都是 http2,并给出了在服务器端禁用它的指示,作为一种变通方法。现在,为了给其他建设性意见(或答案)腾出空间,我们删除了旧的,我将它们重新整理为下面的单独答案。

Grizzly 的 http2 过滤器似乎运行不正常(让我们暂时假设一下)。您的 Firefox 屏幕截图显示 HTTP/2.0。 NetBeans 服务器监视器工作正常可能是因为它不支持 http2,因此在这种情况下您的服务器会回退到 HTTP/1.1(编辑:那只是一个假设,最近的评论暗示它 可能 支持 http2...)

Grizzly 从 2.4.0 开始支持 HTTP2,但您必须 explicitly enable it... and GlassFish does that by default

How to configure Glassfish5 to send several Set-Cookie headers - one for each cookie?

虽然 Glassfish/Grizzly 团队致力于 fixing the (apparent) bug,但您可以在 GlassFish 中禁用 http2 作为解决方法。

假设您的 HTTPS 侦听器是 http-listener-2 您可以从命令行执行此操作:

asadmin set server.network-config.protocols.protocol.http-listener-2.htt‌​p.http2-enabled=fals‌​e

据我所知,此设置尚未记录,我从 this @Attribute in source code (and followed it through the code until GenericGrizzlyListener). In addition, it seems that attribute is not exposed in the admin console so I see no other way than using asadmin set as above (please note the "Version" attribute is a distinct 设置中推断出上面的命令。

我的研究是基于"latest promoted build"(当时b19,"latest nightly"就是b20)。 GitHub 的链接指向 b19.

问题现在已由专业的 glassfish 团队解决 - 我们应该将文件 nucleus-grizzly-all.jar 文件更改为新文件 - 在 GitHub 可用 here。再次 - 非常感谢 glassfish 开发团队!

您不再需要那个自定义的 nucleus-grizzly-all.jar。该问题已作为最新 Glassfish 5.0 nightlys 和最新升级版本的一部分发布。

有两个不同的问题,因为我跟踪了 Grizzly 问题的实际修复并使用 GlassFish 问题来集成 Grizzly。