在HTTP规范中,分隔cookie的字符串是什么?

发布于 2024-10-14 21:16:33 字数 57 浏览 3 评论 0原文

分号 ;Cookie: 字符串还是其他字符串?

Semicolon ;, the Cookie: string or some other string?

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

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

发布评论

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

评论(2

滴情不沾 2024-10-21 21:16:33

检查 HTTP 请求中的 Cookie

Cookie: 标头具有以下语法:

Cookie: <Name> = <Value> { ; <Name> = <Value> }

因此各个 Cookie 是分开的 带有分号和空格

在 HTTP 响应中设置 cookie

另一方面,在响应中设置 cookie 时,每个 Set-Cookie: 标头有一个 cookie:

Set-Cookie: <Name> = <Value> [ ; expires = <Date>] [ ; path = <Path> ] [ ; domain = <Domain> ] // etc…

要设置多个 cookie,请使用 Set-CookieSet-Cookie code> 标头在 HTTP 响应中重复。


注意:

  • 请查看此处,获取包含示例的教程,并RFC 6265 HTTP 状态管理机制作为规范性参考,显示了完整的详细信息语法。
  • 现在已过时的 RFC 2965 定义了一对备用标头 Cookie2 和 Set-Cookie2 已被放弃。
  • HTTP 状态管理机制的过时版本 (RFC 2109RFC 2965) 提供了一种折叠多个 Set-Cookie< 的方法/code> (或 Set-Cookie2) 标头合二为一。但是,最新的 RFC 6265 规范不推荐这种折叠。

Inspecting cookies in an HTTP request

The Cookie: header has the following syntax:

Cookie: <Name> = <Value> { ; <Name> = <Value> }

Hence individual cookies are separated with the semicolon and a space.

Setting cookies in an HTTP response

On the other hand, when setting a cookie in the response, there one cookie per the Set-Cookie: header:

Set-Cookie: <Name> = <Value> [ ; expires = <Date>] [ ; path = <Path> ] [ ; domain = <Domain> ] // etc…

To set multiple cookies the Set-Cookie header is repeated in an HTTP response.


Notes:

  • Have a look here for a tutorial with examples, and to RFC 6265 HTTP State Management Mechanism for a normative reference showing the full details of the syntax.
  • The now-obsolete RFC 2965 defined an alternate pair of headers Cookie2 and Set-Cookie2 which were abandoned.
  • The obsoleted versions of the HTTP State Management Mechanism (RFC 2109 and RFC 2965) provided a way to fold multiple Set-Cookie (or Set-Cookie2) headers into one. However, this folding is not recommended by the latest RFC 6265 spec.
救赎№ 2024-10-21 21:16:33

答案是逗号,符号。

RFC 2109Set-Cookie 标头的规范,

   set-cookie      =       "Set-Cookie:" cookies
   cookies         =       1#cookie

其中包含以下语句非正式地,Set-Cookie 响应标头包含令牌 Set-Cookie:,后跟一个或多个 Cookie 的逗号分隔列表。(上述表示法中 # 的正式含义定义于 RFC 733 部分 A. 符号约定,第 5 点

定义了一个结构“#”,类似于“*”,如下:

 #元素

表示至少 和最多 个元素,每个元素由
一个或多个逗号 (",")。

是的,RFC 2109 已被 RFC 2965 废弃,而 RFC 2965 又被 RFC 6265 废弃.
不,它不会改变这种情况下的任何内容,因为

  • 大多数现有的 HTTP 服务器和客户端都支持 RFC 2109
  • RFC 6265 不会禁止 Set-Cookie 折叠

The answer is a comma , sign.

In section 4.2.2 of RFC 2109 there's this specification of Set-Cookie header

   set-cookie      =       "Set-Cookie:" cookies
   cookies         =       1#cookie

with the following statement Informally, the Set-Cookie response header comprises the token Set-Cookie:, followed by a comma separated list of one or more cookies. (Formally meaning of # in the above notation is defined in RFC 733 in section A. NOTATIONAL CONVENTIONS, point 5

A construct "#" is defined, similar to "*", as follows:

              <l>#<m>element

indicating at least <l> and at most <m> elements, each separated by
one or more commas (",").

Yes, RFC 2109 was obsoleted by RFC 2965, which in turn was obsoleted by RFC 6265.
No, it doesn't change anything in this context as

  • most existing HTTP servers and clients support RFC 2109
  • RFC 6265 does not forbid Set-Cookie folding
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文