簡體   English   中英

使用 cookies 的節點 http2 請求

[英]node http2 requests with cookies

節點 http2 請求如下所示:

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

似乎不可能像這樣發送多個 cookie 標頭。 我錯過了什么嗎? 請注意,cookies 不應像 http/https 標頭那樣加入。

所以我的理解是,如果客戶端是 HTTP/2,那么你將 cookies 與勞倫斯所說的分號連接起來。 如果服務器也是 HTTP/2,這很好,但是如果服務器是 HTTP/1.1,則需要一些額外的處理來連接它們。

如果解壓后有多個 Cookie header 字段,則必須使用雙字節分隔符 0x3B、0x20(ASCII 字符串“;”)將它們連接成單個八位字節字符串

已通過HTTP2 https://tools.ietf.org/html/rfc7540#section-8.1.2.5規范確認

正如文檔中所說,重復的 cookie 標頭由";"分隔並且set-cookie應該是數組。

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

set-cookie 始終是一個數組。 重復項被添加到數組中。 對於重復的 cookie 標頭,這些值用 '; 連接在一起。 '。

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=/;"'],
} )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM