Skip to content

Commit

Permalink
deps: update undici to 5.21.2
Browse files Browse the repository at this point in the history
PR-URL: #47508
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
nodejs-github-bot authored and danielleadams committed Jul 6, 2023
1 parent cf7ca9b commit d8e4c2e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
37 changes: 25 additions & 12 deletions deps/undici/src/lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions deps/undici/src/lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
26 changes: 20 additions & 6 deletions deps/undici/undici.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -1765,6 +1778,7 @@ var require_headers = __commonJS({
clear() {
this[kHeadersMap].clear();
this[kHeadersSortedMap] = null;
this.cookies = null;
}
append(name, value) {
this[kHeadersSortedMap] = null;
Expand Down
2 changes: 1 addition & 1 deletion src/undici_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

0 comments on commit d8e4c2e

Please sign in to comment.