From f532f9df5fcabb89a823bb67fa1cdf2eb7c2ccbe Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Thu, 13 Apr 2023 13:43:19 +0100 Subject: [PATCH] deps: update undici to 5.21.2 PR-URL: https://github.com/nodejs/node/pull/47508 Reviewed-By: Robert Nagy Reviewed-By: Matthew Aitken Reviewed-By: Matteo Collina Reviewed-By: Jiawen Geng --- deps/undici/src/lib/core/util.js | 37 +++++++++++++++++++--------- deps/undici/src/lib/fetch/headers.js | 1 + deps/undici/src/package.json | 2 +- deps/undici/undici.js | 26 ++++++++++++++----- src/undici_version.h | 2 +- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/deps/undici/src/lib/core/util.js b/deps/undici/src/lib/core/util.js index bfee97946cdf93..6f247d22a524bf 100644 --- a/deps/undici/src/lib/core/util.js +++ b/deps/undici/src/lib/core/util.js @@ -222,40 +222,53 @@ function parseHeaders (headers, obj = {}) { const key = headers[i].toString().toLowerCase() let val = obj[key] - const encoding = key.length === 19 && key === 'content-disposition' - ? 'latin1' - : 'utf8' - if (!val) { if (Array.isArray(headers[i + 1])) { obj[key] = headers[i + 1] } else { - obj[key] = headers[i + 1].toString(encoding) + obj[key] = headers[i + 1].toString('utf8') } } else { if (!Array.isArray(val)) { val = [val] obj[key] = val } - val.push(headers[i + 1].toString(encoding)) + val.push(headers[i + 1].toString('utf8')) } } + + // See https://github.com/nodejs/node/pull/46528 + if ('content-length' in obj && 'content-disposition' in obj) { + obj['content-disposition'] = Buffer.from(obj['content-disposition']).toString('latin1') + } + return obj } function parseRawHeaders (headers) { const ret = [] + let hasContentLength = false + let contentDispositionIdx = -1 + for (let n = 0; n < headers.length; n += 2) { const key = headers[n + 0].toString() + const val = headers[n + 1].toString('utf8') - const encoding = key.length === 19 && key.toLowerCase() === 'content-disposition' - ? 'latin1' - : 'utf8' - - const val = headers[n + 1].toString(encoding) + if (key.length === 14 && (key === 'content-length' || key.toLowerCase() === 'content-length')) { + ret.push(key, val) + hasContentLength = true + } else if (key.length === 19 && (key === 'content-disposition' || key.toLowerCase() === 'content-disposition')) { + contentDispositionIdx = ret.push(key, val) - 1 + } else { + ret.push(key, val) + } + } - ret.push(key, val) + // See https://github.com/nodejs/node/pull/46528 + if (hasContentLength && contentDispositionIdx !== -1) { + ret[contentDispositionIdx] = Buffer.from(ret[contentDispositionIdx]).toString('latin1') } + return ret } diff --git a/deps/undici/src/lib/fetch/headers.js b/deps/undici/src/lib/fetch/headers.js index 5093ef8726f2a0..b42a5edeaabea7 100644 --- a/deps/undici/src/lib/fetch/headers.js +++ b/deps/undici/src/lib/fetch/headers.js @@ -95,6 +95,7 @@ class HeadersList { clear () { this[kHeadersMap].clear() this[kHeadersSortedMap] = null + this.cookies = null } // https://fetch.spec.whatwg.org/#concept-header-list-append diff --git a/deps/undici/src/package.json b/deps/undici/src/package.json index 79aa9b2758cb4a..f0eb689718698d 100644 --- a/deps/undici/src/package.json +++ b/deps/undici/src/package.json @@ -1,6 +1,6 @@ { "name": "undici", - "version": "5.21.1", + "version": "5.21.2", "description": "An HTTP/1.1 client, written from scratch for Node.js", "homepage": "https://undici.nodejs.org", "bugs": { diff --git a/deps/undici/undici.js b/deps/undici/undici.js index 105d7a83fadda8..41c18cc725ab79 100644 --- a/deps/undici/undici.js +++ b/deps/undici/undici.js @@ -443,30 +443,43 @@ var require_util = __commonJS({ for (let i = 0; i < headers.length; i += 2) { const key = headers[i].toString().toLowerCase(); let val = obj[key]; - const encoding = key.length === 19 && key === "content-disposition" ? "latin1" : "utf8"; if (!val) { if (Array.isArray(headers[i + 1])) { obj[key] = headers[i + 1]; } else { - obj[key] = headers[i + 1].toString(encoding); + obj[key] = headers[i + 1].toString("utf8"); } } else { if (!Array.isArray(val)) { val = [val]; obj[key] = val; } - val.push(headers[i + 1].toString(encoding)); + val.push(headers[i + 1].toString("utf8")); } } + if ("content-length" in obj && "content-disposition" in obj) { + obj["content-disposition"] = Buffer.from(obj["content-disposition"]).toString("latin1"); + } return obj; } function parseRawHeaders(headers) { const ret = []; + let hasContentLength = false; + let contentDispositionIdx = -1; for (let n = 0; n < headers.length; n += 2) { const key = headers[n + 0].toString(); - const encoding = key.length === 19 && key.toLowerCase() === "content-disposition" ? "latin1" : "utf8"; - const val = headers[n + 1].toString(encoding); - ret.push(key, val); + const val = headers[n + 1].toString("utf8"); + if (key.length === 14 && (key === "content-length" || key.toLowerCase() === "content-length")) { + ret.push(key, val); + hasContentLength = true; + } else if (key.length === 19 && (key === "content-disposition" || key.toLowerCase() === "content-disposition")) { + contentDispositionIdx = ret.push(key, val) - 1; + } else { + ret.push(key, val); + } + } + if (hasContentLength && contentDispositionIdx !== -1) { + ret[contentDispositionIdx] = Buffer.from(ret[contentDispositionIdx]).toString("latin1"); } return ret; } @@ -1765,6 +1778,7 @@ var require_headers = __commonJS({ clear() { this[kHeadersMap].clear(); this[kHeadersSortedMap] = null; + this.cookies = null; } append(name, value) { this[kHeadersSortedMap] = null; diff --git a/src/undici_version.h b/src/undici_version.h index 84fcd207a4481a..04719b18858d04 100644 --- a/src/undici_version.h +++ b/src/undici_version.h @@ -2,5 +2,5 @@ // Refer to tools/update-undici.sh #ifndef SRC_UNDICI_VERSION_H_ #define SRC_UNDICI_VERSION_H_ -#define UNDICI_VERSION "5.21.1" +#define UNDICI_VERSION "5.21.2" #endif // SRC_UNDICI_VERSION_H_