Skip to content

Commit 732f8b9

Browse files
nodejs-github-botmarco-ippolito
authored andcommitted
deps: update undici to 6.11.1
PR-URL: #52328 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com.com>
1 parent 29093e2 commit 732f8b9

14 files changed

+129
-119
lines changed

deps/undici/src/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ An HTTP/1.1 client, written from scratch for Node.js.
77
> Undici means eleven in Italian. 1.1 -> 11 -> Eleven -> Undici.
88
It is also a Stranger Things reference.
99

10+
## How to get involved
11+
1012
Have a question about using Undici? Open a [Q&A Discussion](https://github.com/nodejs/undici/discussions/new) or join our official OpenJS [Slack](https://openjs-foundation.slack.com/archives/C01QF9Q31QD) channel.
1113

14+
Looking to contribute? Start by reading the [contributing guide](./CONTRIBUTING.md)
15+
1216
## Install
1317

1418
```

deps/undici/src/lib/core/util.js

-3
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ function bufferToLowerCasedHeaderName (value) {
246246
* @returns {Record<string, string | string[]>}
247247
*/
248248
function parseHeaders (headers, obj) {
249-
// For H2 support
250-
if (!Array.isArray(headers)) return headers
251-
252249
if (obj === undefined) obj = {}
253250
for (let i = 0; i < headers.length; i += 2) {
254251
const key = headerNameToString(headers[i])

deps/undici/src/lib/dispatcher/client-h2.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ const {
5454
}
5555
} = http2
5656

57+
function parseH2Headers (headers) {
58+
// set-cookie is always an array. Duplicates are added to the array.
59+
// For duplicate cookie headers, the values are joined together with '; '.
60+
headers = Object.entries(headers).flat(2)
61+
62+
const result = []
63+
64+
for (const header of headers) {
65+
result.push(Buffer.from(header))
66+
}
67+
68+
return result
69+
}
70+
5771
async function connectH2 (client, socket) {
5872
client[kSocket] = socket
5973

@@ -391,7 +405,19 @@ function writeH2 (client, request) {
391405
const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers
392406
request.onResponseStarted()
393407

394-
if (request.onHeaders(Number(statusCode), realHeaders, stream.resume.bind(stream), '') === false) {
408+
// Due to the stream nature, it is possible we face a race condition
409+
// where the stream has been assigned, but the request has been aborted
410+
// the request remains in-flight and headers hasn't been received yet
411+
// for those scenarios, best effort is to destroy the stream immediately
412+
// as there's no value to keep it open.
413+
if (request.aborted || request.completed) {
414+
const err = new RequestAbortedError()
415+
errorRequest(client, request, err)
416+
util.destroy(stream, err)
417+
return
418+
}
419+
420+
if (request.onHeaders(Number(statusCode), parseH2Headers(realHeaders), stream.resume.bind(stream), '') === false) {
395421
stream.pause()
396422
}
397423

deps/undici/src/lib/handler/redirect-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ function shouldRemoveHeader (header, removeContent, unknownOrigin) {
201201
if (removeContent && util.headerNameToString(header).startsWith('content-')) {
202202
return true
203203
}
204-
if (unknownOrigin && (header.length === 13 || header.length === 6)) {
204+
if (unknownOrigin && (header.length === 13 || header.length === 6 || header.length === 19)) {
205205
const name = util.headerNameToString(header)
206-
return name === 'authorization' || name === 'cookie'
206+
return name === 'authorization' || name === 'cookie' || name === 'proxy-authorization'
207207
}
208208
return false
209209
}

deps/undici/src/lib/mock/pending-interceptors-formatter.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const { Transform } = require('node:stream')
44
const { Console } = require('node:console')
55

6+
const PERSISTENT = process.versions.icu ? '✅' : 'Y '
7+
const NOT_PERSISTENT = process.versions.icu ? '❌' : 'N '
8+
69
/**
710
* Gets the output of `console.table(…)` as a string.
811
*/
@@ -29,7 +32,7 @@ module.exports = class PendingInterceptorsFormatter {
2932
Origin: origin,
3033
Path: path,
3134
'Status code': statusCode,
32-
Persistent: persist ? '✅' : '❌',
35+
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
3336
Invocations: timesInvoked,
3437
Remaining: persist ? Infinity : times - timesInvoked
3538
}))

deps/undici/src/lib/web/fetch/data-url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const encoder = new TextEncoder()
88
* @see https://mimesniff.spec.whatwg.org/#http-token-code-point
99
*/
1010
const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-Za-z0-9]+$/
11-
const HTTP_WHITESPACE_REGEX = /[\u000A|\u000D|\u0009|\u0020]/ // eslint-disable-line
11+
const HTTP_WHITESPACE_REGEX = /[\u000A\u000D\u0009\u0020]/ // eslint-disable-line
1212
const ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g // eslint-disable-line
1313
/**
1414
* @see https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
1515
*/
16-
const HTTP_QUOTED_STRING_TOKENS = /[\u0009|\u0020-\u007E|\u0080-\u00FF]/ // eslint-disable-line
16+
const HTTP_QUOTED_STRING_TOKENS = /[\u0009\u0020-\u007E\u0080-\u00FF]/ // eslint-disable-line
1717

1818
// https://fetch.spec.whatwg.org/#data-url-processor
1919
/** @param {URL} dataURL */

deps/undici/src/lib/web/fetch/headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
} = require('./util')
1313
const { webidl } = require('./webidl')
1414
const assert = require('node:assert')
15-
const util = require('util')
15+
const util = require('node:util')
1616

1717
const kHeadersMap = Symbol('headers map')
1818
const kHeadersSortedMap = Symbol('headers map sorted')

deps/undici/src/lib/web/fetch/index.js

-23
Original file line numberDiff line numberDiff line change
@@ -2141,29 +2141,6 @@ async function httpNetworkFetch (
21412141
codings = contentEncoding.toLowerCase().split(',').map((x) => x.trim())
21422142
}
21432143
location = headersList.get('location', true)
2144-
} else {
2145-
const keys = Object.keys(rawHeaders)
2146-
for (let i = 0; i < keys.length; ++i) {
2147-
// The header names are already in lowercase.
2148-
const key = keys[i]
2149-
const value = rawHeaders[key]
2150-
if (key === 'set-cookie') {
2151-
for (let j = 0; j < value.length; ++j) {
2152-
headersList.append(key, value[j], true)
2153-
}
2154-
} else {
2155-
headersList.append(key, value, true)
2156-
}
2157-
}
2158-
// For H2, The header names are already in lowercase,
2159-
// so we can avoid the `HeadersList#get` call here.
2160-
const contentEncoding = rawHeaders['content-encoding']
2161-
if (contentEncoding) {
2162-
// https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1
2163-
// "All content-coding values are case-insensitive..."
2164-
codings = contentEncoding.toLowerCase().split(',').map((x) => x.trim()).reverse()
2165-
}
2166-
location = rawHeaders.location
21672144
}
21682145

21692146
this.body = new Readable({ read: resume })

deps/undici/src/lib/web/fetch/util.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ let supportedHashes = []
1818
let crypto
1919
try {
2020
crypto = require('node:crypto')
21+
const possibleRelevantHashes = ['sha256', 'sha384', 'sha512']
22+
supportedHashes = crypto.getHashes().filter((hash) => possibleRelevantHashes.includes(hash))
2123
/* c8 ignore next 3 */
2224
} catch {
2325
}
@@ -615,7 +617,7 @@ function bytesMatch (bytes, metadataList) {
615617
// https://w3c.github.io/webappsec-subresource-integrity/#grammardef-hash-with-options
616618
// https://www.w3.org/TR/CSP2/#source-list-syntax
617619
// https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1
618-
const parseHashWithOptions = /(?<algo>sha256|sha384|sha512)-(?<hash>[A-Za-z0-9+/]+={0,2}(?=\s|$))( +[!-~]*)?/i
620+
const parseHashWithOptions = /(?<algo>sha256|sha384|sha512)-((?<hash>[A-Za-z0-9+/]+|[A-Za-z0-9_-]+)={0,2}(?:\s|$)( +[!-~]*)?)?/i
619621

620622
/**
621623
* @see https://w3c.github.io/webappsec-subresource-integrity/#parse-metadata

0 commit comments

Comments
 (0)