deps: update undici to 6.16.1 · nodejs/node@fe00bec · GitHub
Skip to content

Commit fe00bec

Browse files
nodejs-github-bottargos
authored andcommitted
deps: update undici to 6.16.1
PR-URL: #52948 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent ee56aec commit fe00bec

29 files changed

Lines changed: 1028 additions & 589 deletions
Lines changed: 162 additions & 0 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Receives a header object and returns the parsed value.
88

99
Arguments:
1010

11-
- **headers** `Record<string, string | string[]> | (Buffer | string | (Buffer | string)[])[]` (required) - Header object.
11+
- **headers** `(Buffer | string | (Buffer | string)[])[]` (required) - Header object.
1212

1313
- **obj** `Record<string, string | string[]>` (optional) - Object to specify a proxy object. The parsed value is assigned to this object. But, if **headers** is an object, it is not used.
1414

15-
Returns: `Record<string, string | string[]>` If **headers** is an object, it is **headers**. Otherwise, if **obj** is specified, it is equivalent to **obj**.
15+
Returns: `Record<string, string | string[]>` If **obj** is specified, it is equivalent to **obj**.
1616

1717
## `headerNameToString(value)`
1818

deps/undici/src/docs/docs/best-practices/proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Connecting through a proxy is possible by:
44

5-
- Using [AgentProxy](../api/ProxyAgent.md).
5+
- Using [ProxyAgent](../api/ProxyAgent.md).
66
- Configuring `Client` or `Pool` constructor.
77

88
The proxy url should be passed to the `Client` or `Pool` constructor, while the upstream server url

deps/undici/src/lib/api/api-request.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
const assert = require('node:assert')
44
const { Readable } = require('./readable')
5-
const { InvalidArgumentError } = require('../core/errors')
5+
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
66
const util = require('../core/util')
77
const { getResolveErrorBodyCallback } = require('./util')
88
const { AsyncResource } = require('node:async_hooks')
9-
const { addSignal, removeSignal } = require('./abort-signal')
109

1110
class RequestHandler extends AsyncResource {
1211
constructor (opts, callback) {
@@ -45,6 +44,7 @@ class RequestHandler extends AsyncResource {
4544
throw err
4645
}
4746

47+
this.method = method
4848
this.responseHeaders = responseHeaders || null
4949
this.opaque = opaque || null
5050
this.callback = callback
@@ -56,14 +56,36 @@ class RequestHandler extends AsyncResource {
5656
this.onInfo = onInfo || null
5757
this.throwOnError = throwOnError
5858
this.highWaterMark = highWaterMark
59+
this.signal = signal
60+
this.reason = null
61+
this.removeAbortListener = null
5962

6063
if (util.isStream(body)) {
6164
body.on('error', (err) => {
6265
this.onError(err)
6366
})
6467
}
6568

66-
addSignal(this, signal)
69+
if (this.signal) {
70+
if (this.signal.aborted) {
71+
this.reason = this.signal.reason ?? new RequestAbortedError()
72+
} else {
73+
this.removeAbortListener = util.addAbortListener(this.signal, () => {
74+
this.reason = this.signal.reason ?? new RequestAbortedError()
75+
if (this.res) {
76+
util.destroy(this.res, this.reason)
77+
} else if (this.abort) {
78+
this.abort(this.reason)
79+
}
80+
81+
if (this.removeAbortListener) {
82+
this.res?.off('close', this.removeAbortListener)
83+
this.removeAbortListener()
84+
this.removeAbortListener = null
85+
}
86+
})
87+
}
88+
}
6789
}
6890

6991
onConnect (abort, context) {
@@ -93,48 +115,52 @@ class RequestHandler extends AsyncResource {
93115
const parsedHeaders = responseHeaders === 'raw' ? util.parseHeaders(rawHeaders) : headers
94116
const contentType = parsedHeaders['content-type']
95117
const contentLength = parsedHeaders['content-length']
96-
const body = new Readable({ resume, abort, contentType, contentLength, highWaterMark })
118+
const res = new Readable({
119+
resume,
120+
abort,
121+
contentType,
122+
contentLength: this.method !== 'HEAD' && contentLength
123+
? Number(contentLength)
124+
: null,
125+
highWaterMark
126+
})
127+
128+
if (this.removeAbortListener) {
129+
res.on('close', this.removeAbortListener)
130+
}
97131

98132
this.callback = null
99-
this.res = body
133+
this.res = res
100134
if (callback !== null) {
101135
if (this.throwOnError && statusCode >= 400) {
102136
this.runInAsyncScope(getResolveErrorBodyCallback, null,
103-
{ callback, body, contentType, statusCode, statusMessage, headers }
137+
{ callback, body: res, contentType, statusCode, statusMessage, headers }
104138
)
105139
} else {
106140
this.runInAsyncScope(callback, null, null, {
107141
statusCode,
108142
headers,
109143
trailers: this.trailers,
110144
opaque,
111-
body,
145+
body: res,
112146
context
113147
})
114148
}
115149
}
116150
}
117151

118152
onData (chunk) {
119-
const { res } = this
120-
return res.push(chunk)
153+
return this.res.push(chunk)
121154
}
122155

123156
onComplete (trailers) {
124-
const { res } = this
125-
126-
removeSignal(this)
127-
128157
util.parseHeaders(trailers, this.trailers)
129-
130-
res.push(null)
158+
this.res.push(null)
131159
}
132160

133161
onError (err) {
134162
const { res, callback, body, opaque } = this
135163

136-
removeSignal(this)
137-
138164
if (callback) {
139165
// TODO: Does this need queueMicrotask?
140166
this.callback = null
@@ -155,6 +181,12 @@ class RequestHandler extends AsyncResource {
155181
this.body = null
156182
util.destroy(body, err)
157183
}
184+
185+
if (this.removeAbortListener) {
186+
res?.off('close', this.removeAbortListener)
187+
this.removeAbortListener()
188+
this.removeAbortListener = null
189+
}
158190
}
159191
}
160192

deps/undici/src/lib/api/readable.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ class BodyReadable extends Readable {
6363
// tick as it is created, then a user who is waiting for a
6464
// promise (i.e micro tick) for installing a 'error' listener will
6565
// never get a chance and will always encounter an unhandled exception.
66-
setImmediate(() => {
66+
if (!this[kReading]) {
67+
setImmediate(() => {
68+
callback(err)
69+
})
70+
} else {
6771
callback(err)
68-
})
72+
}
6973
}
7074

7175
on (ev, ...args) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function setupTimeout (onConnectTimeout, timeout) {
165165
let s1 = null
166166
let s2 = null
167167
const timeoutId = setTimeout(() => {
168-
// setImmediate is added to make sure that we priotorise socket error events over timeouts
168+
// setImmediate is added to make sure that we prioritize socket error events over timeouts
169169
s1 = setImmediate(() => {
170170
if (process.platform === 'win32') {
171171
// Windows needs an extra setImmediate probably due to implementation differences in the socket logic

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

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)