Skip to content

Commit 4a17dda

Browse files
nodejs-github-botRafaelGSS
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 7c66b27 commit 4a17dda

11 files changed

Lines changed: 310 additions & 233 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,72 @@
11
'use strict'
22

33
constassert=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
conststream=require('node:stream')
77
constnet=require('node:net')
8-
const{ InvalidArgumentError }=require('./errors')
98
const{ Blob }=require('node:buffer')
109
constnodeUtil=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+
classBodyAsyncIterable{
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+
functionwrapRequestBody(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(typeofbody.readableDidRead!=='boolean'){
44+
body[kBodyUsed]=false
45+
EE.prototype.on.call(body,'data',function(){
46+
this[kBodyUsed]=true
47+
})
48+
}
49+
50+
returnbody
51+
}elseif(body&&typeofbody.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+
returnnewBodyAsyncIterable(body)
56+
}elseif(
57+
body&&
58+
typeofbody!=='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+
returnnewBodyAsyncIterable(body)
65+
}else{
66+
returnbody
67+
}
68+
}
69+
1770
functionnop(){}
1871

1972
functionisStream(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‎

Lines changed: 11 additions & 4 deletions
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
functioncalculateRetryAfterHeader(retryAfter){
914
constcurrent=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
newRequestRetryError('Request failed',statusCode,{
176181
headers,
177-
count: this.retryCount
182+
data: {
183+
count: this.retryCount
184+
}
178185
})
179186
)
180187
returnfalse
@@ -278,7 +285,7 @@ class RetryHandler {
278285

279286
consterr=newRequestRetryError('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‎

Lines changed: 3 additions & 4 deletions
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-
constcookies=getHeadersList(headers).cookies
81+
constcookies=headers.getSetCookie()
8282

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

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

9190
/**

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
constassert=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
returnout.join('; ')
276273
}
277274

278-
letkHeadersListNode
279-
280-
functiongetHeadersList(headers){
281-
try{
282-
returninternalGetHeadersList(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-
constheadersList=headers[kHeadersListNode]
296-
assert(headersList)
297-
298-
returnheadersList
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‎

Lines changed: 0 additions & 8 deletions
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-
returngetHeadersList(this)
651-
}
652644
}
653645
})
654646

0 commit comments

Comments
 (0)