Skip to content

Commit 7ed50e5

Browse files
authored
deps: update undici to v5.26.3
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #50153 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 224f3ae commit 7ed50e5

File tree

14 files changed

+963
-446
lines changed

14 files changed

+963
-446
lines changed

deps/undici/src/docs/api/Client.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Returns: `Client`
2424
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
2525
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
2626
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
27-
* **maxHeaderSize** `number | null` (optional) - Default: `16384` - The maximum length of request headers in bytes. Defaults to 16KiB.
27+
* **maxHeaderSize** `number | null` (optional) - Default: `--max-http-header-size` or `16384` - The maximum length of request headers in bytes. Defaults to Node.js' --max-http-header-size or 16KiB.
2828
* **maxResponseSize** `number | null` (optional) - Default: `-1` - The maximum length of response body in bytes. Set to `-1` to disable.
2929
* **pipelining** `number | null` (optional) - Default: `1` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections.
3030
* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.

deps/undici/src/lib/client.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const assert = require('assert')
88
const net = require('net')
9+
const http = require('http')
910
const { pipeline } = require('stream')
1011
const util = require('./core/util')
1112
const timers = require('./timers')
@@ -93,6 +94,7 @@ const {
9394
HTTP2_HEADER_AUTHORITY,
9495
HTTP2_HEADER_METHOD,
9596
HTTP2_HEADER_PATH,
97+
HTTP2_HEADER_SCHEME,
9698
HTTP2_HEADER_CONTENT_LENGTH,
9799
HTTP2_HEADER_EXPECT,
98100
HTTP2_HEADER_STATUS
@@ -269,7 +271,7 @@ class Client extends DispatcherBase {
269271
this[kConnector] = connect
270272
this[kSocket] = null
271273
this[kPipelining] = pipelining != null ? pipelining : 1
272-
this[kMaxHeadersSize] = maxHeaderSize || 16384
274+
this[kMaxHeadersSize] = maxHeaderSize || http.maxHeaderSize
273275
this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
274276
this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
275277
this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 1e3 : keepAliveTimeoutThreshold
@@ -1689,7 +1691,7 @@ function writeH2 (client, session, request) {
16891691
const h2State = client[kHTTP2SessionState]
16901692

16911693
headers[HTTP2_HEADER_AUTHORITY] = host || client[kHost]
1692-
headers[HTTP2_HEADER_PATH] = path
1694+
headers[HTTP2_HEADER_METHOD] = method
16931695

16941696
if (method === 'CONNECT') {
16951697
session.ref()
@@ -1716,10 +1718,14 @@ function writeH2 (client, session, request) {
17161718
})
17171719

17181720
return true
1719-
} else {
1720-
headers[HTTP2_HEADER_METHOD] = method
17211721
}
17221722

1723+
// https://tools.ietf.org/html/rfc7540#section-8.3
1724+
// :path and :scheme headers must be omited when sending CONNECT
1725+
1726+
headers[HTTP2_HEADER_PATH] = path
1727+
headers[HTTP2_HEADER_SCHEME] = 'https'
1728+
17231729
// https://tools.ietf.org/html/rfc7231#section-4.3.1
17241730
// https://tools.ietf.org/html/rfc7231#section-4.3.2
17251731
// https://tools.ietf.org/html/rfc7231#section-4.3.5
@@ -1856,6 +1862,7 @@ function writeH2 (client, session, request) {
18561862
stream.cork()
18571863
stream.write(body)
18581864
stream.uncork()
1865+
stream.end()
18591866
request.onBodySent(body)
18601867
request.onRequestSent()
18611868
} else if (util.isBlobLike(body)) {
@@ -2090,13 +2097,17 @@ async function writeIterable ({ h2stream, body, client, request, socket, content
20902097
throw socket[kError]
20912098
}
20922099

2093-
if (!h2stream.write(chunk)) {
2100+
const res = h2stream.write(chunk)
2101+
request.onBodySent(chunk)
2102+
if (!res) {
20942103
await waitForDrain()
20952104
}
20962105
}
20972106
} catch (err) {
20982107
h2stream.destroy(err)
20992108
} finally {
2109+
request.onRequestSent()
2110+
h2stream.end()
21002111
h2stream
21012112
.off('close', onDrain)
21022113
.off('drain', onDrain)

deps/undici/src/lib/compat/dispatcher-weakref.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class CompatFinalizer {
2222
}
2323

2424
register (dispatcher, key) {
25-
dispatcher.on('disconnect', () => {
26-
if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
27-
this.finalizer(key)
28-
}
29-
})
25+
if (dispatcher.on) {
26+
dispatcher.on('disconnect', () => {
27+
if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
28+
this.finalizer(key)
29+
}
30+
})
31+
}
3032
}
3133
}
3234

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ function processHeader (request, key, val, skipAppend = false) {
381381
key.toLowerCase() === 'content-type'
382382
) {
383383
request.contentType = val
384-
request.headers += processHeaderValue(key, val)
384+
if (skipAppend) request.headers[key] = processHeaderValue(key, val, skipAppend)
385+
else request.headers += processHeaderValue(key, val)
385386
} else if (
386387
key.length === 17 &&
387388
key.toLowerCase() === 'transfer-encoding'

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,10 @@ async function httpRedirectFetch (fetchParams, response) {
12001200
if (!sameOrigin(requestCurrentURL(request), locationURL)) {
12011201
// https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
12021202
request.headersList.delete('authorization')
1203+
1204+
// "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
1205+
request.headersList.delete('cookie')
1206+
request.headersList.delete('host')
12031207
}
12041208

12051209
// 14. If request’s body is non-null, then set request’s body to the first return
@@ -1344,7 +1348,7 @@ async function httpNetworkOrCacheFetch (
13441348
// user agents should append `User-Agent`/default `User-Agent` value to
13451349
// httpRequest’s header list.
13461350
if (!httpRequest.headersList.contains('user-agent')) {
1347-
httpRequest.headersList.append('user-agent', 'undici')
1351+
httpRequest.headersList.append('user-agent', typeof esbuildDetection === 'undefined' ? 'undici' : 'node')
13481352
}
13491353

13501354
// 15. If httpRequest’s cache mode is "default" and httpRequest’s header
@@ -1406,6 +1410,8 @@ async function httpNetworkOrCacheFetch (
14061410
}
14071411
}
14081412

1413+
httpRequest.headersList.delete('host')
1414+
14091415
// 20. If includeCredentials is true, then:
14101416
if (includeCredentials) {
14111417
// 1. If the user agent is not configured to block cookies for httpRequest

deps/undici/src/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undici",
3-
"version": "5.25.4",
3+
"version": "5.26.3",
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"homepage": "https://undici.nodejs.org",
66
"bugs": {
@@ -67,15 +67,16 @@
6767
"index-fetch.js",
6868
"lib",
6969
"types",
70-
"docs"
70+
"docs",
71+
"scripts/esbuild-build.mjs"
7172
],
7273
"scripts": {
73-
"build:node": "npx esbuild@0.14.38 index-fetch.js --bundle --platform=node --outfile=undici-fetch.js",
74+
"build:node": "node scripts/esbuild-build.mjs",
7475
"prebuild:wasm": "node build/wasm.js --prebuild",
7576
"build:wasm": "node build/wasm.js --docker",
7677
"lint": "standard | snazzy",
7778
"lint:fix": "standard --fix | snazzy",
78-
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript",
79+
"test": "node scripts/generate-pem && npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript",
7980
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
8081
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha --exit test/node-fetch",
8182
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
@@ -109,6 +110,7 @@
109110
"delay": "^5.0.0",
110111
"dns-packet": "^5.4.0",
111112
"docsify-cli": "^4.4.3",
113+
"esbuild": "^0.19.4",
112114
"form-data": "^4.0.0",
113115
"formdata-node": "^4.3.1",
114116
"https-pem": "^3.0.0",
@@ -122,7 +124,8 @@
122124
"pre-commit": "^1.2.2",
123125
"proxy": "^1.0.2",
124126
"proxyquire": "^2.1.3",
125-
"sinon": "^15.0.0",
127+
"semver": "^7.5.4",
128+
"sinon": "^16.1.0",
126129
"snazzy": "^9.0.0",
127130
"standard": "^17.0.0",
128131
"table": "^6.8.0",
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as esbuild from 'esbuild'
2+
import fs from 'node:fs'
3+
4+
const bundle = {
5+
name: 'bundle',
6+
setup (build) {
7+
build.onLoad({ filter: /lib(\/|\\)fetch(\/|\\)index.js/ }, async (args) => {
8+
const text = await fs.promises.readFile(args.path, 'utf8')
9+
10+
return {
11+
contents: `var esbuildDetection = 1;${text}`,
12+
loader: 'js'
13+
}
14+
})
15+
}
16+
}
17+
18+
await esbuild.build({
19+
entryPoints: ['index-fetch.js'],
20+
bundle: true,
21+
outfile: 'undici-fetch.js',
22+
plugins: [bundle],
23+
platform: 'node'
24+
})

deps/undici/src/types/agent.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare class Agent extends Dispatcher{
1717
declare namespace Agent {
1818
export interface Options extends Pool.Options {
1919
/** Default: `(origin, opts) => new Pool(origin, opts)`. */
20-
factory?(origin: URL, opts: Object): Dispatcher;
20+
factory?(origin: string | URL, opts: Object): Dispatcher;
2121
/** Integer. Default: `0` */
2222
maxRedirections?: number;
2323

deps/undici/src/types/client.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export declare namespace Client {
2323
export interface Options {
2424
/** TODO */
2525
interceptors?: OptionsInterceptors;
26-
/** The maximum length of request headers in bytes. Default: `16384` (16KiB). */
26+
/** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
2727
maxHeaderSize?: number;
2828
/** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
2929
headersTimeout?: number;

deps/undici/src/types/connector.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare function buildConnector (options?: buildConnector.BuildOptions): buildCo
66

77
declare namespace buildConnector {
88
export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & {
9+
allowH2?: boolean;
910
maxCachedSessions?: number | null;
1011
socketPath?: string | null;
1112
timeout?: number | null;

0 commit comments

Comments
 (0)