Skip to content

Commit 0be84e5

Browse files
nodejs-github-botUlisesGascon
authored andcommitted
deps: update undici to 5.27.2
PR-URL: #50813 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Matthew Aitken <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ec67890 commit 0be84e5

File tree

12 files changed

+1262
-228
lines changed

12 files changed

+1262
-228
lines changed

‎deps/undici/src/lib/client.js‎

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,23 +1462,7 @@ function _resume (client, sync){
14621462
return
14631463
}
14641464

1465-
if(util.isStream(request.body)&&util.bodyLength(request.body)===0){
1466-
request.body
1467-
.on('data',/* istanbul ignore next */function(){
1468-
/* istanbul ignore next */
1469-
assert(false)
1470-
})
1471-
.on('error',function(err){
1472-
errorRequest(client,request,err)
1473-
})
1474-
.on('end',function(){
1475-
util.destroy(this)
1476-
})
1477-
1478-
request.body=null
1479-
}
1480-
1481-
if(client[kRunning]>0&&
1465+
if(client[kRunning]>0&&util.bodyLength(request.body)!==0&&
14821466
(util.isStream(request.body)||util.isAsyncIterable(request.body))){
14831467
// Request with stream or iterator body can error while other requests
14841468
// are inflight and indirectly error those as well.
@@ -1499,6 +1483,11 @@ function _resume (client, sync){
14991483
}
15001484
}
15011485

1486+
// https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2
1487+
functionshouldSendContentLength(method){
1488+
returnmethod!=='GET'&&method!=='HEAD'&&method!=='OPTIONS'&&method!=='TRACE'&&method!=='CONNECT'
1489+
}
1490+
15021491
functionwrite(client,request){
15031492
if(client[kHTTPConnVersion]==='h2'){
15041493
writeH2(client,client[kHTTP2Session],request)
@@ -1527,7 +1516,9 @@ function write (client, request){
15271516
body.read(0)
15281517
}
15291518

1530-
letcontentLength=util.bodyLength(body)
1519+
constbodyLength=util.bodyLength(body)
1520+
1521+
letcontentLength=bodyLength
15311522

15321523
if(contentLength===null){
15331524
contentLength=request.contentLength
@@ -1542,7 +1533,9 @@ function write (client, request){
15421533
contentLength=null
15431534
}
15441535

1545-
if(request.contentLength!==null&&request.contentLength!==contentLength){
1536+
// https://github.com/nodejs/undici/issues/2046
1537+
// A user agent may send a Content-Length header with 0 value, this should be allowed.
1538+
if(shouldSendContentLength(method)&&contentLength>0&&request.contentLength!==null&&request.contentLength!==contentLength){
15461539
if(client[kStrictContentLength]){
15471540
errorRequest(client,request,newRequestContentLengthMismatchError())
15481541
returnfalse
@@ -1623,7 +1616,7 @@ function write (client, request){
16231616
}
16241617

16251618
/* istanbul ignore else: assertion */
1626-
if(!body){
1619+
if(!body||bodyLength===0){
16271620
if(contentLength===0){
16281621
socket.write(`${header}content-length: 0\r\n\r\n`,'latin1')
16291622
}else{
@@ -1763,7 +1756,9 @@ function writeH2 (client, session, request){
17631756
contentLength=null
17641757
}
17651758

1766-
if(request.contentLength!=null&&request.contentLength!==contentLength){
1759+
// https://github.com/nodejs/undici/issues/2046
1760+
// A user agent may send a Content-Length header with 0 value, this should be allowed.
1761+
if(shouldSendContentLength(method)&&contentLength>0&&request.contentLength!=null&&request.contentLength!==contentLength){
17671762
if(client[kStrictContentLength]){
17681763
errorRequest(client,request,newRequestContentLengthMismatchError())
17691764
returnfalse

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,29 @@ class Request{
112112

113113
this.method=method
114114

115+
this.abort=null
116+
115117
if(body==null){
116118
this.body=null
117119
}elseif(util.isStream(body)){
118120
this.body=body
121+
122+
constrState=this.body._readableState
123+
if(!rState||!rState.autoDestroy){
124+
this.endHandler=functionautoDestroy(){
125+
util.destroy(this)
126+
}
127+
this.body.on('end',this.endHandler)
128+
}
129+
130+
this.errorHandler=err=>{
131+
if(this.abort){
132+
this.abort(err)
133+
}else{
134+
this.error=err
135+
}
136+
}
137+
this.body.on('error',this.errorHandler)
119138
}elseif(util.isBuffer(body)){
120139
this.body=body.byteLength ? body : null
121140
}elseif(ArrayBuffer.isView(body)){
@@ -236,7 +255,12 @@ class Request{
236255
assert(!this.aborted)
237256
assert(!this.completed)
238257

239-
returnthis[kHandler].onConnect(abort)
258+
if(this.error){
259+
abort(this.error)
260+
}else{
261+
this.abort=abort
262+
returnthis[kHandler].onConnect(abort)
263+
}
240264
}
241265

242266
onHeaders(statusCode,headers,resume,statusText){
@@ -265,6 +289,8 @@ class Request{
265289
}
266290

267291
onComplete(trailers){
292+
this.onFinally()
293+
268294
assert(!this.aborted)
269295

270296
this.completed=true
@@ -275,6 +301,8 @@ class Request{
275301
}
276302

277303
onError(error){
304+
this.onFinally()
305+
278306
if(channels.error.hasSubscribers){
279307
channels.error.publish({request: this, error })
280308
}
@@ -286,6 +314,18 @@ class Request{
286314
returnthis[kHandler].onError(error)
287315
}
288316

317+
onFinally(){
318+
if(this.errorHandler){
319+
this.body.off('error',this.errorHandler)
320+
this.errorHandler=null
321+
}
322+
323+
if(this.endHandler){
324+
this.body.off('end',this.endHandler)
325+
this.endHandler=null
326+
}
327+
}
328+
289329
// TODO: adjust to support H2
290330
addHeader(key,value){
291331
processHeader(this,key,value)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function isReadableAborted (stream){
190190
}
191191

192192
functiondestroy(stream,err){
193-
if(!isStream(stream)||isDestroyed(stream)){
193+
if(stream==null||!isStream(stream)||isDestroyed(stream)){
194194
return
195195
}
196196

‎deps/undici/src/lib/pool.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Pool extends PoolBase{
5757
maxCachedSessions,
5858
allowH2,
5959
socketPath,
60-
timeout: connectTimeout==null ? 10e3 : connectTimeout,
60+
timeout: connectTimeout,
6161
...(util.nodeHasAutoSelectFamily&&autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
6262
...connect
6363
})

‎deps/undici/src/node_modules/@fastify/busboy/lib/utils/decodeText.js‎

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)