From b3894f9bf59da166d9d3c492632c99e2d430bf57 Mon Sep 17 00:00:00 2001 From: ofir Date: Fri, 28 Jan 2022 23:13:54 +0200 Subject: [PATCH] http2: fix pseudo-headers order Keep pseudo-headers order same as sent order Fixes: https://github.com/nodejs/node/issues/38797 --- lib/internal/http2/util.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 78ff2937c3a317..38578d2a151c52 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -472,7 +472,8 @@ const kNeverIndexFlag = StringFromCharCode(NGHTTP2_NV_FLAG_NO_INDEX); const kNoHeaderFlags = StringFromCharCode(NGHTTP2_NV_FLAG_NONE); function mapToHeaders(map, assertValuePseudoHeader = assertValidPseudoHeader) { - let ret = ''; + let headers = ''; + let pseudoHeaders = ''; let count = 0; const keys = ObjectKeys(map); const singles = new SafeSet(); @@ -520,7 +521,7 @@ function mapToHeaders(map, err = assertValuePseudoHeader(key); if (err !== undefined) throw err; - ret = `${key}\0${value}\0${flags}${ret}`; + pseudoHeaders += `${key}\0${value}\0${flags}`; count++; continue; } @@ -533,16 +534,16 @@ function mapToHeaders(map, if (isArray) { for (j = 0; j < value.length; ++j) { const val = String(value[j]); - ret += `${key}\0${val}\0${flags}`; + headers += `${key}\0${val}\0${flags}`; } count += value.length; continue; } - ret += `${key}\0${value}\0${flags}`; + headers += `${key}\0${value}\0${flags}`; count++; } - return [ret, count]; + return [pseudoHeaders + headers, count]; } class NghttpError extends Error {