解析Set-Cookie标头的firefox源代码的位置?

发布于 2024-09-08 06:58:38 字数 913 浏览 1 评论 0原文

有人可以给我指出解析 Set-Cookie 标头的 Firefox 源代码吗?我想了解确切的行为。

如果您想知道原因,请进一步阅读? 对于我的应用程序中的各种约束,我需要在单个 Set-Cookie 标头中传递多个 cookie。 RFC-2109 明确提到,

“Set-Cookie 响应标头包含令牌 Set-Cookie:,后跟一个或多个 cookie 的逗号分隔列表。每个 cookie 以 NAME=VALUE 对开头,后跟零个或多个分号分隔的属性-值对。”

所以我应该能够传递以下 Set-Cookie 标头

Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12,名称2=值2; attr21=attrval21; attr22=attrval22;

这不起作用。但是,以下设置确实有效

Set-Cookie: name1=value1, name2=value2; attr1=attrval1; attr2=attrval2;

而且,我想为不同的cookie赋予不同的属性。

[更新]

真实示例

示例#1-

Set-Cookie: cookie1=value1;路径=/,cookie2=值2; Path=/

在这种情况下,firefox 解析并获取第一个 cookie(其名称为“cookie1”,值为“value1”)(第二个完全被忽略)

示例#2-

Set-Cookie: cookie1=value1,cookie2=值2; Path=/

在这种情况下,firefox 认为有一个 cookie,其名称为“cookie1”,值为“value1,cookie2=value2”。这又不是我们的初衷。

Can someone please point me to the Firefox source code where Set-Cookie header is parsed? I want to understand the exact behavior.

Read further if you want to know why?
For various constraint in my application, I need to pass multiple cookies inside single Set-Cookie header. RFC-2109 clearly mentions,

"Set-Cookie response header comprises the token Set-Cookie:, followed by a comma-separated list of one or more cookies. Each cookie begins with a NAME=VALUE pair, followed by zero or more semi-colon-separated attribute-value pairs."

So I should be able to pass following Set-Cookie header

Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12,name2=value2; attr21=attrval21; attr22=attrval22;

It doesn't work. However, following does work

Set-Cookie: name1=value1, name2=value2; attr1=attrval1; attr2=attrval2;

And, I want to give different attributes for different cookies.

[Update]

Real Examples:

Example#1-

Set-Cookie: cookie1=value1; Path=/,cookie2=value2; Path=/

In this case firefox parses and gets first cookie(whose name is "cookie1" and value is "value1") out of it(second one is completely ignored)

Example#2-

Set-Cookie: cookie1=value1,cookie2=value2; Path=/

In this case firefox believes there is one cookie whose name is "cookie1" and value is "value1,cookie2=value2". This, again, is not what was intended.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖不如嘢 2024-09-15 06:58:38

快速浏览一下 MXR 表明主要逻辑位于 nsCookieService::SetCookieInternal。您可以根据需要来回点击链接。就您的实际问题而言,如果您提供一个真实的示例标题可能会有所帮助。

A quick walk through MXR indicates the main logic is in nsCookieService::SetCookieInternal. You can follow the links back and forth as needed. As far as your actual problem, it may help if you give a real example header.

北方的韩爷 2024-09-15 06:58:38

我的理解是,浏览器对每个 Set-Cookie 标头的多个 cookie 的标准实现有些不同。但是,您可以发送多个 Set-Cookie 标头来设置多个 cookie 的值:

Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12
Set-Cookie: name2=value2; attr21=attrval21; attr22=attrval22

尽管您有任何理由手动将标头发送到响应而不是使用您的框架(PHP、ASP.NET)。 NET、RoR 等)提供了什么?

My understanding is that browsers implement the standard somewhat differently in respect to multiple cookies per Set-Cookie header. However, you can send multiple Set-Cookie headers to set the value of multiple cookies:

Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12
Set-Cookie: name2=value2; attr21=attrval21; attr22=attrval22

Although is there any reason why you're manually headers to the response instead of using whatever your framework (PHP, ASP.NET, RoR, etc) provides?

記憶穿過時間隧道 2024-09-15 06:58:38

好吧,从源代码中可以清楚地看到,firefox 在这方面没有实现 RFC-2109,并使用 CR 或 LF 而不是 ',' 作为 cookie 分隔符(注意 http://mxr.mozilla.org/mozilla-central/source/netwerk/cookie/ nsCookieService.cpp)。我在 Firefox v3.6.6 上尝试了两者,CR 可以工作,但 LF 不能。

结论:在 Firefox 上,我可以使用 CR 代替“,”来分隔 cookie。

小故障:(CR、LF、'、')中没有一个正在 Internet-Explorer 上工作。现在有人可以向我指出 IE 的“源”代码吗?在那里我可以看到他们使用什么作为 cookie 分隔符:-)

well, reading from the source code its clear that firefox doesn't implement RFC-2109 in this regard and uses CR or LF instead of ',' as cookie separator(notice line#1934, 1959, 1990 in http://mxr.mozilla.org/mozilla-central/source/netwerk/cookie/nsCookieService.cpp). I tried both on Firefox v3.6.6, CR is working but LF is not.

Conclusion: on Firefox, I can use CR instead of ',' to separate cookies.

Glitch : None out of (CR, LF, ',') are working on Internet-Explorer. Now can someone point me to "source" code for IE where I can see what they're using as cookie separator :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文