我需要什么(TL;DR):
我需要請求標頭與我在 http2 請求選項中指定的完全相同,它應該保留名稱大小寫和所有標頭的順序。
如何在發送請求之前明確設定此順序或修改它們?如果默認的“http2”庫無法使用,請讓我知道任何其他能夠執行此操作的庫。
如果您需要更多背景關系,請繼續閱讀!
現在會發生什么:
當我使用“http2”庫執行 HTTP/2.0 請求時,所有標題名稱似乎都被規范化為小寫,并且在發送請求之前它的順序發生了變化。
我用來執行 HTTP/2.0 請求的示例代碼:
const http2 = require('http2');
const client = http2.connect('http://localhost:8000');
const request = client.request({
':method': 'GET',
':authority': 'localhost:8000',
':scheme': 'https',
':path': '/',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua': `" Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"`,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36',
'Cookie': 'foo=bar',
});
request.end()
我希望在服務器上收到的標頭訂單:
:method: GET
:authority': localhost:8000
:scheme': https
:path: /
sec-ch-ua-mobile: ?0
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Cookie: foo=bar
我在服務器上實際收到的內容:
:path: /
:scheme: https
:authority: localhost:8000
:method: GET
sec-ch-ua-mobile: ?0
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
cookie: foo=bar
Note that the casing of all headers and the order of :path, :scheme, :authority and :method headers are different from what i expect them to be...
I already investigated the source code of http2, seems it is not possible to explicitly define the order of this 4 headers and disable this naming lowercase normalization. Many of the existing HTTP/2.0 libraries for node relly on the native lib, thus, carring this problem with them.
But here we goes nothing, how can i explicitly set this header order or modify them before the request is sent to match what i expect? Exists any library or library binding that allow a way to achive this in Node JS?
PS: already tried node-libcurl and it have the same problem.
Thanks!
uj5u.com熱心網友回復:
從HTTP/2 規范:
就像在 HTTP/1.x 中一樣,標頭欄位名稱是 ASCII 字串,它們以不區分大小寫的方式進行比較。但是,在 HTTP/2 中編碼之前,必須將標頭欄位名稱轉換為小寫。包含大寫標題欄位名稱的請求或回應必須被視為格式錯誤
我不知道有關訂購的任何類似限制,但我也會說取決于訂單是一個壞主意,因為我也不知道它被明確保留。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/443173.html
標籤:javascript node.js http https http2
上一篇:FastAPI拒絕來自javascript代碼但不來自3rd方請求應用程式的POST請求(失眠)
下一篇:收到HTTP400回應
