简体   繁体   中英

node http2 requests with cookies

Node http2 requests look like this:

const client = http2.connect('https://somehost.com')
const req = client.request( {
  ':path': '/some/path',
  ':method': 'GET',
  'header-name': 'header-value',
  'cookie': 'foo=bar'  
} )

It doesn't seem possible to send multiple cookie headers like this. Am I missing something? Note that the cookies should not get joined like in http/https headers.

So my understanding is that if the client is HTTP/2 then you concatenate cookies with a semicolon like Lawrence said. Which is fine if the server is also HTTP/2, however if the server is HTTP/1.1 there will need to be some extra processing to concatenate them.

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 "; ")

Confirmed by the spec for HTTP2 https://tools.ietf.org/html/rfc7540#section-8.1.2.5

As it is said in doc, duplicate cookie headers separated by ";"and set-cookie should be array.

https://nodejs.org/api/http2.html#http2_headers_object

set-cookie is always an array. Duplicates are added to the array. For duplicate cookie headers, the values are joined together with '; '.

const client = http2.connect('https://somehost.com')
const req = client.request( {
  ':path': '/some/path',
  ':method': 'GET',
  'header-name': 'header-value',
  'Set-Cookie': ['ting="tang; expires=0; path=/;"', 'wallawalla="bingbang; expires=123456789; path=/;"'],
} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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