在HTTP请求允许多个cookie头?(Are multiple Cookie headers al

2019-09-01 13:30发布

通常情况下,一个浏览器的cookie组成一个单一Cookie报头,如:

Cookie: a=1; b=2

是否标准允许把这些作为单独的标题,比如:

Cookie: a=1
Cookie: b=2

还是他们总是要在同一行?

Answer 1:

在此页面偶然而寻找的话题的详细信息。 从A报价HTTP State Management Mechanism , RFC 6265应该让事情更清晰:

5.4。 小甜饼报头

当用户代理产生一个HTTP请求,用户代理必须不附着多个cookie头字段。

它看起来像使用多个Cookie其实,禁止!



Answer 2:

它现在允许HTTP / 2( RFC 7540 ),其指定:

    8.1.2.5.  Compressing the Cookie Header Field

   The Cookie header field [COOKIE] uses a semi-colon (";") to delimit
   cookie-pairs (or "crumbs").  This header field doesn't follow the
   list construction rules in HTTP (see [RFC7230], Section 3.2.2), which
   prevents cookie-pairs from being separated into different name-value
   pairs.  This can significantly reduce compression efficiency as
   individual cookie-pairs are updated.

   To allow for better compression efficiency, the Cookie header field
   MAY be split into separate header fields, each with one or more
   cookie-pairs.  If there are multiple Cookie header fields after
   decompression, these MUST be concatenated into a single octet string
   using the two-octet delimiter of 0x3B, 0x20 (the ASCII string "; ")
   before being passed into a non-HTTP/2 context, such as an HTTP/1.1
   connection, or a generic HTTP server application.

   Therefore, the following two lists of Cookie header fields are
   semantically equivalent.

     cookie: a=b; c=d; e=f

     cookie: a=b
     cookie: c=d
     cookie: e=f


文章来源: Are multiple Cookie headers allowed in an HTTP request?
标签: http cookies