Skip to content

Commit 80cbe72

Browse files
nodejs-github-botaduh95
authored andcommitted
deps: update undici to 6.13.0
PR-URL: #52493 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 3df3afc commit 80cbe72

30 files changed

+1011
-2466
lines changed

deps/undici/src/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ const data = {
248248
await fetch('https://example.com', { body: data, method: 'POST', duplex: 'half' })
249249
```
250250

251+
[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) besides text data and buffers can also utilize streams via [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects:
252+
253+
```js
254+
import { openAsBlob } from 'node:fs'
255+
256+
const file = await openAsBlob('./big.csv')
257+
const body = new FormData()
258+
body.set('file', file, 'big.csv')
259+
260+
await fetch('http://example.com', { method: 'POST', body })
261+
```
262+
251263
#### `request.duplex`
252264

253265
- half

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

+6
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,12 @@ Parameters:
969969
* **targets** `Array<Dispatcher>`
970970
* **error** `Error`
971971

972+
Emitted when the dispatcher has been disconnected from the origin.
973+
974+
> **Note**: For HTTP/2, this event is also emitted when the dispatcher has received the [GOAWAY Frame](https://webconcepts.info/concepts/http2-frame-type/0x7) with an Error with the message `HTTP/2: "GOAWAY" frame received` and the code `UND_ERR_INFO`.
975+
> Due to nature of the protocol of using binary frames, it is possible that requests gets hanging as a frame can be received between the `HEADER` and `DATA` frames.
976+
> It is recommended to handle this event and close the dispatcher to create a new HTTP/2 session.
977+
972978
### Event: `'connectionError'`
973979

974980
Parameters:

deps/undici/src/lib/api/abort-signal.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ function abort (self) {
88
if (self.abort) {
99
self.abort(self[kSignal]?.reason)
1010
} else {
11-
self.onError(self[kSignal]?.reason ?? new RequestAbortedError())
11+
self.reason = self[kSignal]?.reason ?? new RequestAbortedError()
1212
}
13+
removeSignal(self)
1314
}
1415

1516
function addSignal (self, signal) {
17+
self.reason = null
18+
1619
self[kSignal] = null
1720
self[kListener] = null
1821

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict'
22

3+
const assert = require('node:assert')
34
const { AsyncResource } = require('node:async_hooks')
4-
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
5+
const { InvalidArgumentError, SocketError } = require('../core/errors')
56
const util = require('../core/util')
67
const { addSignal, removeSignal } = require('./abort-signal')
78

@@ -32,10 +33,13 @@ class ConnectHandler extends AsyncResource {
3233
}
3334

3435
onConnect (abort, context) {
35-
if (!this.callback) {
36-
throw new RequestAbortedError()
36+
if (this.reason) {
37+
abort(this.reason)
38+
return
3739
}
3840

41+
assert(this.callback)
42+
3943
this.abort = abort
4044
this.context = context
4145
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,14 @@ class PipelineHandler extends AsyncResource {
147147
onConnect (abort, context) {
148148
const { ret, res } = this
149149

150-
assert(!res, 'pipeline cannot be retried')
151-
152-
if (ret.destroyed) {
153-
throw new RequestAbortedError()
150+
if (this.reason) {
151+
abort(this.reason)
152+
return
154153
}
155154

155+
assert(!res, 'pipeline cannot be retried')
156+
assert(!ret.destroyed)
157+
156158
this.abort = abort
157159
this.context = context
158160
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict'
22

3+
const assert = require('node:assert')
34
const { Readable } = require('./readable')
4-
const {
5-
InvalidArgumentError,
6-
RequestAbortedError
7-
} = require('../core/errors')
5+
const { InvalidArgumentError } = require('../core/errors')
86
const util = require('../core/util')
97
const { getResolveErrorBodyCallback } = require('./util')
108
const { AsyncResource } = require('node:async_hooks')
@@ -69,10 +67,13 @@ class RequestHandler extends AsyncResource {
6967
}
7068

7169
onConnect (abort, context) {
72-
if (!this.callback) {
73-
throw new RequestAbortedError()
70+
if (this.reason) {
71+
abort(this.reason)
72+
return
7473
}
7574

75+
assert(this.callback)
76+
7677
this.abort = abort
7778
this.context = context
7879
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
'use strict'
22

3+
const assert = require('node:assert')
34
const { finished, PassThrough } = require('node:stream')
4-
const {
5-
InvalidArgumentError,
6-
InvalidReturnValueError,
7-
RequestAbortedError
8-
} = require('../core/errors')
5+
const { InvalidArgumentError, InvalidReturnValueError } = require('../core/errors')
96
const util = require('../core/util')
107
const { getResolveErrorBodyCallback } = require('./util')
118
const { AsyncResource } = require('node:async_hooks')
@@ -70,10 +67,13 @@ class StreamHandler extends AsyncResource {
7067
}
7168

7269
onConnect (abort, context) {
73-
if (!this.callback) {
74-
throw new RequestAbortedError()
70+
if (this.reason) {
71+
abort(this.reason)
72+
return
7573
}
7674

75+
assert(this.callback)
76+
7777
this.abort = abort
7878
this.context = context
7979
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
3+
const { InvalidArgumentError, SocketError } = require('../core/errors')
44
const { AsyncResource } = require('node:async_hooks')
55
const util = require('../core/util')
66
const { addSignal, removeSignal } = require('./abort-signal')
@@ -34,10 +34,13 @@ class UpgradeHandler extends AsyncResource {
3434
}
3535

3636
onConnect (abort, context) {
37-
if (!this.callback) {
38-
throw new RequestAbortedError()
37+
if (this.reason) {
38+
abort(this.reason)
39+
return
3940
}
4041

42+
assert(this.callback)
43+
4144
this.abort = abort
4245
this.context = null
4346
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ 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-
// - tick => process.nextTick(fn)
67-
// - micro tick => queueMicrotask(fn)
68-
queueMicrotask(() => {
66+
setImmediate(() => {
6967
callback(err)
7068
})
7169
}

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

+41-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const assert = require('node:assert')
4-
const { kDestroyed, kBodyUsed } = require('./symbols')
4+
const { kDestroyed, kBodyUsed, kListeners } = require('./symbols')
55
const { IncomingMessage } = require('node:http')
66
const stream = require('node:stream')
77
const net = require('node:net')
@@ -22,13 +22,20 @@ function isStream (obj) {
2222

2323
// based on https://github.com/node-fetch/fetch-blob/blob/8ab587d34080de94140b54f07168451e7d0b655e/index.js#L229-L241 (MIT License)
2424
function isBlobLike (object) {
25-
return (Blob && object instanceof Blob) || (
26-
object &&
27-
typeof object === 'object' &&
28-
(typeof object.stream === 'function' ||
29-
typeof object.arrayBuffer === 'function') &&
30-
/^(Blob|File)$/.test(object[Symbol.toStringTag])
31-
)
25+
if (object === null) {
26+
return false
27+
} else if (object instanceof Blob) {
28+
return true
29+
} else if (typeof object !== 'object') {
30+
return false
31+
} else {
32+
const sTag = object[Symbol.toStringTag]
33+
34+
return (sTag === 'Blob' || sTag === 'File') && (
35+
('stream' in object && typeof object.stream === 'function') ||
36+
('arrayBuffer' in object && typeof object.arrayBuffer === 'function')
37+
)
38+
}
3239
}
3340

3441
function buildURL (url, queryParams) {
@@ -534,6 +541,29 @@ function parseRangeHeader (range) {
534541
: null
535542
}
536543

544+
function addListener (obj, name, listener) {
545+
const listeners = (obj[kListeners] ??= [])
546+
listeners.push([name, listener])
547+
obj.on(name, listener)
548+
return obj
549+
}
550+
551+
function removeAllListeners (obj) {
552+
for (const [name, listener] of obj[kListeners] ?? []) {
553+
obj.removeListener(name, listener)
554+
}
555+
obj[kListeners] = null
556+
}
557+
558+
function errorRequest (client, request, err) {
559+
try {
560+
request.onError(err)
561+
assert(request.aborted)
562+
} catch (err) {
563+
client.emit('error', err)
564+
}
565+
}
566+
537567
const kEnumerableProperty = Object.create(null)
538568
kEnumerableProperty.enumerable = true
539569

@@ -556,6 +586,9 @@ module.exports = {
556586
isDestroyed,
557587
headerNameToString,
558588
bufferToLowerCasedHeaderName,
589+
addListener,
590+
removeAllListeners,
591+
errorRequest,
559592
parseRawHeaders,
560593
parseHeaders,
561594
parseKeepAliveTimeout,

0 commit comments

Comments
 (0)