Skip to content

Commit a6b803a

Browse files
nodejs-github-botmarco-ippolito
authored andcommitted
deps: update undici to 6.18.2
PR-URL: #53255 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent d02651c commit a6b803a

File tree

11 files changed

+310
-233
lines changed

11 files changed

+310
-233
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ It represents the retry state for a given request.
4646
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every retry.
4747
- **handler** Extends [`Dispatch.DispatchHandlers`](Dispatcher.md#dispatcherdispatchoptions-handler) (required) - Handler function to be called after the request is successful or the retries are exhausted.
4848

49+
>__Note__: The `RetryHandler` does not retry over stateful bodies (e.g. streams, AsyncIterable) as those, once consumed, are left in an state that cannot be reutilized. For these situations the `RetryHandler` will identify
50+
>the body as stateful and will not retry the request rejecting with the error `UND_ERR_REQ_RETRY`.
51+
4952
Examples:
5053

5154
```js

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
kHost: Symbol('host'),
2121
kNoRef: Symbol('no ref'),
2222
kBodyUsed: Symbol('used'),
23+
kBody: Symbol('abstracted request body'),
2324
kRunning: Symbol('running'),
2425
kBlocking: Symbol('blocking'),
2526
kPending: Symbol('pending'),

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

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

33
const assert = require('node:assert')
4-
const { kDestroyed, kBodyUsed, kListeners } = require('./symbols')
4+
const { kDestroyed, kBodyUsed, kListeners, kBody } = require('./symbols')
55
const { IncomingMessage } = require('node:http')
66
const stream = require('node:stream')
77
const net = require('node:net')
8-
const { InvalidArgumentError } = require('./errors')
98
const { Blob } = require('node:buffer')
109
const nodeUtil = require('node:util')
1110
const { stringify } = require('node:querystring')
11+
const { EventEmitter: EE } = require('node:events')
12+
const { InvalidArgumentError } = require('./errors')
1213
const { headerNameLowerCasedRecord } = require('./constants')
1314
const { tree } = require('./tree')
1415

1516
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v))
1617

18+
class BodyAsyncIterable {
19+
constructor (body) {
20+
this[kBody] = body
21+
this[kBodyUsed] = false
22+
}
23+
24+
async * [Symbol.asyncIterator] () {
25+
assert(!this[kBodyUsed], 'disturbed')
26+
this[kBodyUsed] = true
27+
yield * this[kBody]
28+
}
29+
}
30+
31+
function wrapRequestBody (body) {
32+
if (isStream(body)) {
33+
// TODO (fix): Provide some way for the user to cache the file to e.g. /tmp
34+
// so that it can be dispatched again?
35+
// TODO (fix): Do we need 100-expect support to provide a way to do this properly?
36+
if (bodyLength(body) === 0) {
37+
body
38+
.on('data', function () {
39+
assert(false)
40+
})
41+
}
42+
43+
if (typeof body.readableDidRead !== 'boolean') {
44+
body[kBodyUsed] = false
45+
EE.prototype.on.call(body, 'data', function () {
46+
this[kBodyUsed] = true
47+
})
48+
}
49+
50+
return body
51+
} else if (body && typeof body.pipeTo === 'function') {
52+
// TODO (fix): We can't access ReadableStream internal state
53+
// to determine whether or not it has been disturbed. This is just
54+
// a workaround.
55+
return new BodyAsyncIterable(body)
56+
} else if (
57+
body &&
58+
typeof body !== 'string' &&
59+
!ArrayBuffer.isView(body) &&
60+
isIterable(body)
61+
) {
62+
// TODO: Should we allow re-using iterable if !this.opts.idempotent
63+
// or through some other flag?
64+
return new BodyAsyncIterable(body)
65+
} else {
66+
return body
67+
}
68+
}
69+
1770
function nop () {}
1871

1972
function isStream (obj) {
@@ -634,5 +687,6 @@ module.exports = {
634687
isHttpOrHttpsPrefixed,
635688
nodeMajor,
636689
nodeMinor,
637-
safeHTTPMethods: ['GET', 'HEAD', 'OPTIONS', 'TRACE']
690+
safeHTTPMethods: ['GET', 'HEAD', 'OPTIONS', 'TRACE'],
691+
wrapRequestBody
638692
}

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ const assert = require('node:assert')
33

44
const { kRetryHandlerDefaultRetry } = require('../core/symbols')
55
const { RequestRetryError } = require('../core/errors')
6-
const { isDisturbed, parseHeaders, parseRangeHeader } = require('../core/util')
6+
const {
7+
isDisturbed,
8+
parseHeaders,
9+
parseRangeHeader,
10+
wrapRequestBody
11+
} = require('../core/util')
712

813
function calculateRetryAfterHeader (retryAfter) {
914
const current = Date.now()
@@ -29,7 +34,7 @@ class RetryHandler {
2934

3035
this.dispatch = handlers.dispatch
3136
this.handler = handlers.handler
32-
this.opts = dispatchOpts
37+
this.opts = { ...dispatchOpts, body: wrapRequestBody(opts.body) }
3338
this.abort = null
3439
this.aborted = false
3540
this.retryOpts = {
@@ -174,7 +179,9 @@ class RetryHandler {
174179
this.abort(
175180
new RequestRetryError('Request failed', statusCode, {
176181
headers,
177-
count: this.retryCount
182+
data: {
183+
count: this.retryCount
184+
}
178185
})
179186
)
180187
return false
@@ -278,7 +285,7 @@ class RetryHandler {
278285

279286
const err = new RequestRetryError('Request failed', statusCode, {
280287
headers,
281-
count: this.retryCount
288+
data: { count: this.retryCount }
282289
})
283290

284291
this.abort(err)

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

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

33
const { parseSetCookie } = require('./parse')
4-
const { stringify, getHeadersList } = require('./util')
4+
const { stringify } = require('./util')
55
const { webidl } = require('../fetch/webidl')
66
const { Headers } = require('../fetch/headers')
77

@@ -78,14 +78,13 @@ function getSetCookies (headers) {
7878

7979
webidl.brandCheck(headers, Headers, { strict: false })
8080

81-
const cookies = getHeadersList(headers).cookies
81+
const cookies = headers.getSetCookie()
8282

8383
if (!cookies) {
8484
return []
8585
}
8686

87-
// In older versions of undici, cookies is a list of name:value.
88-
return cookies.map((pair) => parseSetCookie(Array.isArray(pair) ? pair[1] : pair))
87+
return cookies.map((pair) => parseSetCookie(pair))
8988
}
9089

9190
/**

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

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

3-
const assert = require('node:assert')
4-
const { getHeadersList: internalGetHeadersList } = require('../fetch/headers')
5-
63
/**
74
* @param {string} value
85
* @returns {boolean}
@@ -275,35 +272,11 @@ function stringify (cookie) {
275272
return out.join('; ')
276273
}
277274

278-
let kHeadersListNode
279-
280-
function getHeadersList (headers) {
281-
try {
282-
return internalGetHeadersList(headers)
283-
} catch {
284-
// fall-through
285-
}
286-
287-
if (!kHeadersListNode) {
288-
kHeadersListNode = Object.getOwnPropertySymbols(headers).find(
289-
(symbol) => symbol.description === 'headers list'
290-
)
291-
292-
assert(kHeadersListNode, 'Headers cannot be parsed')
293-
}
294-
295-
const headersList = headers[kHeadersListNode]
296-
assert(headersList)
297-
298-
return headersList
299-
}
300-
301275
module.exports = {
302276
isCTLExcludingHtab,
303277
validateCookieName,
304278
validateCookiePath,
305279
validateCookieValue,
306280
toIMFDate,
307-
stringify,
308-
getHeadersList
281+
stringify
309282
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,6 @@ Object.defineProperties(Headers.prototype, {
641641
},
642642
[util.inspect.custom]: {
643643
enumerable: false
644-
},
645-
// Compatibility for global headers
646-
[Symbol('headers list')]: {
647-
configurable: false,
648-
enumerable: false,
649-
get: function () {
650-
return getHeadersList(this)
651-
}
652644
}
653645
})
654646

0 commit comments

Comments
 (0)