Skip to content

Commit c7ac11f

Browse files
nodejs-github-botTrott
authored andcommitted
deps: update undici to 5.0.0
PR-URL: #42583 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 85a65c3 commit c7ac11f

File tree

20 files changed

+1576
-1538
lines changed

20 files changed

+1576
-1538
lines changed

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

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ const mockAgent = new MockAgent()
7272
setGlobalDispatcher(mockAgent)
7373

7474
constmockPool=mockAgent.get('http://localhost:3000')
75-
76-
mockPool.intercept({
77-
path:'/foo',
78-
method:'GET'
79-
}).reply(200, 'foo')
75+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
8076

8177
const{statusCode, body } =awaitrequest('http://localhost:3000/foo')
8278

@@ -95,11 +91,7 @@ import{MockAgent, request } from 'undici'
9591
constmockAgent=newMockAgent()
9692

9793
constmockPool=mockAgent.get('http://localhost:3000')
98-
99-
mockPool.intercept({
100-
path:'/foo',
101-
method:'GET'
102-
}).reply(200, 'foo')
94+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
10395

10496
const{
10597
statusCode,
@@ -121,11 +113,7 @@ import{MockAgent, request } from 'undici'
121113
constmockAgent=newMockAgent()
122114

123115
constmockPool=mockAgent.get('http://localhost:3000')
124-
125-
mockPool.intercept({
126-
path:'/foo',
127-
method:'GET'
128-
}).reply(200, 'foo')
116+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
129117

130118
const{
131119
statusCode,
@@ -147,11 +135,7 @@ import{MockAgent, request } from 'undici'
147135
constmockAgent=newMockAgent({connections:1 })
148136

149137
constmockClient=mockAgent.get('http://localhost:3000')
150-
151-
mockClient.intercept({
152-
path:'/foo',
153-
method:'GET'
154-
}).reply(200, 'foo')
138+
mockClient.intercept({path:'/foo' }).reply(200, 'foo')
155139

156140
const{
157141
statusCode,
@@ -174,16 +158,8 @@ const mockAgent = new MockAgent()
174158
setGlobalDispatcher(mockAgent)
175159

176160
constmockPool=mockAgent.get('http://localhost:3000')
177-
178-
mockPool.intercept({
179-
path:'/foo',
180-
method:'GET'
181-
}).reply(200, 'foo')
182-
183-
mockPool.intercept({
184-
path:'/hello',
185-
method:'GET'
186-
}).reply(200, 'hello')
161+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
162+
mockPool.intercept({path:'/hello'}).reply(200, 'hello')
187163

188164
constresult1=awaitrequest('http://localhost:3000/foo')
189165

@@ -250,11 +226,7 @@ const mockAgent = new MockAgent()
250226
setGlobalDispatcher(mockAgent)
251227

252228
constmockPool=mockAgent.get(newRegExp('http://localhost:3000'))
253-
254-
mockPool.intercept({
255-
path:'/foo',
256-
method:'GET',
257-
}).reply(200, 'foo')
229+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
258230

259231
const{
260232
statusCode,
@@ -277,11 +249,7 @@ const mockAgent = new MockAgent()
277249
setGlobalDispatcher(mockAgent)
278250

279251
constmockPool=mockAgent.get((origin) => origin ==='http://localhost:3000')
280-
281-
mockPool.intercept({
282-
path:'/foo',
283-
method:'GET'
284-
}).reply(200, 'foo')
252+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
285253

286254
const{
287255
statusCode,
@@ -328,11 +296,7 @@ import{MockAgent } from 'undici'
328296
constmockAgent=newMockAgent()
329297

330298
constmockPool=mockAgent.get('http://localhost:3000')
331-
332-
mockPool.intercept({
333-
path:'/foo',
334-
method:'GET'
335-
}).reply(200, 'foo')
299+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
336300

337301
const{
338302
statusCode,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ import{MockAgent } from 'undici'
5858
constmockAgent=newMockAgent({connections:1 })
5959

6060
constmockClient=mockAgent.get('http://localhost:3000')
61-
mockClient.intercept({
62-
path:'/foo',
63-
method:'GET',
64-
}).reply(200, 'foo')
61+
mockClient.intercept({path:'/foo' }).reply(200, 'foo')
6562

6663
const{
6764
statusCode,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ setGlobalDispatcher(mockAgent)
9595

9696
// MockPool
9797
constmockPool=mockAgent.get('http://localhost:3000')
98-
99-
mockPool.intercept({
100-
path:'/foo',
101-
method:'GET',
102-
}).reply(200, 'foo')
98+
mockPool.intercept({path:'/foo' }).reply(200, 'foo')
10399

104100
const{
105101
statusCode,

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

Lines changed: 30 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
'use strict'
22

3-
const{
4-
ClientClosedError,
5-
InvalidArgumentError,
6-
ClientDestroyedError
7-
}=require('./core/errors')
8-
const{ kClients, kRunning }=require('./core/symbols')
9-
constDispatcher=require('./dispatcher')
3+
const{ InvalidArgumentError }=require('./core/errors')
4+
const{ kClients, kRunning, kClose, kDestroy, kDispatch }=require('./core/symbols')
5+
constDispatcherBase=require('./dispatcher-base')
106
constPool=require('./pool')
117
constClient=require('./client')
128
constutil=require('./core/util')
139
constRedirectHandler=require('./handler/redirect')
1410
const{ WeakRef, FinalizationRegistry }=require('./compat/dispatcher-weakref')()
1511

16-
constkDestroyed=Symbol('destroyed')
17-
constkClosed=Symbol('closed')
1812
constkOnConnect=Symbol('onConnect')
1913
constkOnDisconnect=Symbol('onDisconnect')
2014
constkOnConnectionError=Symbol('onConnectionError')
@@ -30,7 +24,7 @@ function defaultFactory (origin, opts){
3024
: newPool(origin,opts)
3125
}
3226

33-
classAgentextendsDispatcher{
27+
classAgentextendsDispatcherBase{
3428
constructor({ factory =defaultFactory, maxRedirections =0, connect, ...options}={}){
3529
super()
3630

@@ -60,8 +54,6 @@ class Agent extends Dispatcher{
6054
this[kClients].delete(key)
6155
}
6256
})
63-
this[kClosed]=false
64-
this[kDestroyed]=false
6557

6658
constagent=this
6759

@@ -94,76 +86,38 @@ class Agent extends Dispatcher{
9486
returnret
9587
}
9688

97-
dispatch(opts,handler){
98-
if(!handler||typeofhandler!=='object'){
99-
thrownewInvalidArgumentError('handler must be an object.')
89+
[kDispatch](opts,handler){
90+
letkey
91+
if(opts.origin&&(typeofopts.origin==='string'||opts.origininstanceofURL)){
92+
key=String(opts.origin)
93+
}else{
94+
thrownewInvalidArgumentError('opts.origin must be a non-empty string or URL.')
10095
}
10196

102-
try{
103-
if(!opts||typeofopts!=='object'){
104-
thrownewInvalidArgumentError('opts must be an object.')
105-
}
106-
107-
letkey
108-
if(opts.origin&&(typeofopts.origin==='string'||opts.origininstanceofURL)){
109-
key=String(opts.origin)
110-
}else{
111-
thrownewInvalidArgumentError('opts.origin must be a non-empty string or URL.')
112-
}
113-
114-
if(this[kDestroyed]){
115-
thrownewClientDestroyedError()
116-
}
117-
118-
if(this[kClosed]){
119-
thrownewClientClosedError()
120-
}
97+
constref=this[kClients].get(key)
12198

122-
constref=this[kClients].get(key)
123-
124-
letdispatcher=ref ? ref.deref() : null
125-
if(!dispatcher){
126-
dispatcher=this[kFactory](opts.origin,this[kOptions])
127-
.on('drain',this[kOnDrain])
128-
.on('connect',this[kOnConnect])
129-
.on('disconnect',this[kOnDisconnect])
130-
.on('connectionError',this[kOnConnectionError])
131-
132-
this[kClients].set(key,newWeakRef(dispatcher))
133-
this[kFinalizer].register(dispatcher,key)
134-
}
135-
136-
const{ maxRedirections =this[kMaxRedirections]}=opts
137-
if(maxRedirections!=null&&maxRedirections!==0){
138-
opts={ ...opts,maxRedirections: 0}// Stop sub dispatcher from also redirecting.
139-
handler=newRedirectHandler(this,maxRedirections,opts,handler)
140-
}
141-
142-
returndispatcher.dispatch(opts,handler)
143-
}catch(err){
144-
if(typeofhandler.onError!=='function'){
145-
thrownewInvalidArgumentError('invalid onError method')
146-
}
99+
letdispatcher=ref ? ref.deref() : null
100+
if(!dispatcher){
101+
dispatcher=this[kFactory](opts.origin,this[kOptions])
102+
.on('drain',this[kOnDrain])
103+
.on('connect',this[kOnConnect])
104+
.on('disconnect',this[kOnDisconnect])
105+
.on('connectionError',this[kOnConnectionError])
147106

148-
handler.onError(err)
107+
this[kClients].set(key,newWeakRef(dispatcher))
108+
this[kFinalizer].register(dispatcher,key)
149109
}
150-
}
151-
152-
getclosed(){
153-
returnthis[kClosed]
154-
}
155-
156-
getdestroyed(){
157-
returnthis[kDestroyed]
158-
}
159110

160-
close(callback){
161-
if(callback!=null&&typeofcallback!=='function'){
162-
thrownewInvalidArgumentError('callback must be a function')
111+
const{ maxRedirections =this[kMaxRedirections]}=opts
112+
if(maxRedirections!=null&&maxRedirections!==0){
113+
opts={ ...opts,maxRedirections: 0}// Stop sub dispatcher from also redirecting.
114+
handler=newRedirectHandler(this,maxRedirections,opts,handler)
163115
}
164116

165-
this[kClosed]=true
117+
returndispatcher.dispatch(opts,handler)
118+
}
166119

120+
async[kClose](){
167121
constclosePromises=[]
168122
for(constrefofthis[kClients].values()){
169123
constclient=ref.deref()
@@ -173,27 +127,10 @@ class Agent extends Dispatcher{
173127
}
174128
}
175129

176-
if(!callback){
177-
returnPromise.all(closePromises)
178-
}
179-
180-
// Should never error.
181-
Promise.all(closePromises).then(()=>process.nextTick(callback))
130+
awaitPromise.all(closePromises)
182131
}
183132

184-
destroy(err,callback){
185-
if(typeoferr==='function'){
186-
callback=err
187-
err=null
188-
}
189-
190-
if(callback!=null&&typeofcallback!=='function'){
191-
thrownewInvalidArgumentError('callback must be a function')
192-
}
193-
194-
this[kClosed]=true
195-
this[kDestroyed]=true
196-
133+
async[kDestroy](err){
197134
constdestroyPromises=[]
198135
for(constrefofthis[kClients].values()){
199136
constclient=ref.deref()
@@ -203,12 +140,7 @@ class Agent extends Dispatcher{
203140
}
204141
}
205142

206-
if(!callback){
207-
returnPromise.all(destroyPromises)
208-
}
209-
210-
// Should never error.
211-
Promise.all(destroyPromises).then(()=>process.nextTick(callback))
143+
awaitPromise.all(destroyPromises)
212144
}
213145
}
214146

0 commit comments

Comments
(0)