Skip to content

Commit d128356

Browse files
nodejs-github-botBethGriggs
authored andcommitted
deps: update undici to 5.2.0
PR-URL: #43059 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent cec678a commit d128356

14 files changed

Lines changed: 256 additions & 224 deletions

File tree

‎deps/undici/src/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ Basic usage example:
194194
}
195195
```
196196

197+
You can pass an optional dispatcher to `fetch` as:
198+
199+
```js
200+
import { fetch, Agent } from'undici'
201+
202+
constres=awaitfetch('https://example.com', {
203+
// Mocks are also supported
204+
dispatcher:newAgent({
205+
keepAliveTimeout:10,
206+
keepAliveMaxTimeout:10
207+
})
208+
})
209+
constjson=awaitres.json()
210+
console.log(json)
211+
```
197212

198213
#### `request.body`
199214

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { errors } from 'undici'
1919
|`RequestContentLengthMismatchError`|`UND_ERR_REQ_CONTENT_LENGTH_MISMATCH`| request body does not match content-length header |
2020
|`ResponseContentLengthMismatchError`|`UND_ERR_RES_CONTENT_LENGTH_MISMATCH`| response body does not match content-length header |
2121
|`InformationalError`|`UND_ERR_INFO`| expected error with reason |
22-
|`TrailerMismatchError`|`UND_ERR_TRAILER_MISMATCH`| trailers did not match specification |
2322

2423
### `SocketError`
2524

‎deps/undici/src/index-fetch.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use strict'
22

3-
constAgent=require('./lib/agent')
4-
5-
constglobalDispatcher=newAgent()
6-
3+
const{ getGlobalDispatcher }=require('./lib/global')
74
constfetchImpl=require('./lib/fetch')
5+
86
module.exports.fetch=asyncfunctionfetch(resource){
9-
returnfetchImpl.apply(globalDispatcher,arguments)
7+
constdispatcher=(arguments[1]&&arguments[1].dispatcher)||getGlobalDispatcher()
8+
returnfetchImpl.apply(dispatcher,arguments)
109
}
1110
module.exports.FormData=require('./lib/fetch/formdata').FormData
1211
module.exports.Headers=require('./lib/fetch/headers').Headers

‎deps/undici/src/index.js‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const MockAgent = require('./lib/mock/mock-agent')
1515
constMockPool=require('./lib/mock/mock-pool')
1616
constmockErrors=require('./lib/mock/mock-errors')
1717
constProxyAgent=require('./lib/proxy-agent')
18+
const{ getGlobalDispatcher, setGlobalDispatcher }=require('./lib/global')
1819

1920
constnodeVersion=process.versions.node.split('.')
2021
constnodeMajor=Number(nodeVersion[0])
@@ -32,19 +33,6 @@ module.exports.ProxyAgent = ProxyAgent
3233
module.exports.buildConnector=buildConnector
3334
module.exports.errors=errors
3435

35-
letglobalDispatcher=newAgent()
36-
37-
functionsetGlobalDispatcher(agent){
38-
if(!agent||typeofagent.dispatch!=='function'){
39-
thrownewInvalidArgumentError('Argument agent must implement Agent')
40-
}
41-
globalDispatcher=agent
42-
}
43-
44-
functiongetGlobalDispatcher(){
45-
returnglobalDispatcher
46-
}
47-
4836
functionmakeDispatcher(fn){
4937
return(url,opts,handler)=>{
5038
if(typeofopts==='function'){
@@ -98,7 +86,7 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 5)) {
9886
if(!fetchImpl){
9987
fetchImpl=require('./lib/fetch')
10088
}
101-
constdispatcher=getGlobalDispatcher()
89+
constdispatcher=(arguments[1]&&arguments[1].dispatcher)||getGlobalDispatcher()
10290
returnfetchImpl.apply(dispatcher,arguments)
10391
}
10492
module.exports.Headers=require('./lib/fetch/headers').Headers

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const RedirectHandler = require('./handler/redirect')
1111
const{
1212
RequestContentLengthMismatchError,
1313
ResponseContentLengthMismatchError,
14-
TrailerMismatchError,
1514
InvalidArgumentError,
1615
RequestAbortedError,
1716
HeadersTimeoutError,
@@ -425,7 +424,6 @@ class Parser {
425424

426425
this.bytesRead=0
427426

428-
this.trailer=''
429427
this.keepAlive=''
430428
this.contentLength=''
431429
}
@@ -615,8 +613,6 @@ class Parser {
615613
constkey=this.headers[len-2]
616614
if(key.length===10&&key.toString().toLowerCase()==='keep-alive'){
617615
this.keepAlive+=buf.toString()
618-
}elseif(key.length===7&&key.toString().toLowerCase()==='trailer'){
619-
this.trailer+=buf.toString()
620616
}elseif(key.length===14&&key.toString().toLowerCase()==='content-length'){
621617
this.contentLength+=buf.toString()
622618
}
@@ -819,7 +815,7 @@ class Parser {
819815
}
820816

821817
onMessageComplete(){
822-
const{ client, socket, statusCode, upgrade,trailer,headers, contentLength, bytesRead, shouldKeepAlive }=this
818+
const{ client, socket, statusCode, upgrade, headers, contentLength, bytesRead, shouldKeepAlive }=this
823819

824820
if(socket.destroyed&&(!statusCode||shouldKeepAlive)){
825821
return-1
@@ -838,7 +834,6 @@ class Parser {
838834
this.statusText=''
839835
this.bytesRead=0
840836
this.contentLength=''
841-
this.trailer=''
842837
this.keepAlive=''
843838

844839
assert(this.headers.length%2===0)
@@ -849,23 +844,6 @@ class Parser {
849844
return
850845
}
851846

852-
consttrailers=trailer ? trailer.split(/,\s*/) : []
853-
for(leti=0;i<trailers.length;i++){
854-
consttrailer=trailers[i]
855-
letfound=false
856-
for(letn=0;n<headers.length;n+=2){
857-
constkey=headers[n]
858-
if(key.length===trailer.length&&key.toString().toLowerCase()===trailer.toLowerCase()){
859-
found=true
860-
break
861-
}
862-
}
863-
if(!found){
864-
util.destroy(socket,newTrailerMismatchError())
865-
return-1
866-
}
867-
}
868-
869847
/* istanbul ignore next: should be handled by llhttp? */
870848
if(request.method!=='HEAD'&&contentLength&&bytesRead!==parseInt(contentLength,10)){
871849
util.destroy(socket,newResponseContentLengthMismatchError())

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ class ResponseContentLengthMismatchError extends UndiciError {
116116
}
117117
}
118118

119-
classTrailerMismatchErrorextendsUndiciError{
120-
constructor(message){
121-
super(message)
122-
Error.captureStackTrace(this,TrailerMismatchError)
123-
this.name='TrailerMismatchError'
124-
this.message=message||'Trailers does not match trailer header'
125-
this.code='UND_ERR_TRAILER_MISMATCH'
126-
}
127-
}
128-
129119
classClientDestroyedErrorextendsUndiciError{
130120
constructor(message){
131121
super(message)
@@ -196,7 +186,6 @@ module.exports = {
196186
BodyTimeoutError,
197187
RequestContentLengthMismatchError,
198188
ConnectTimeoutError,
199-
TrailerMismatchError,
200189
InvalidArgumentError,
201190
InvalidReturnValueError,
202191
RequestAbortedError,

0 commit comments

Comments
 (0)