@@ -13,14 +13,20 @@ const {
13
13
startRedirectingWithQueryParams
14
14
} = require ( './utils/redirecting-servers' )
15
15
const { createReadable, createReadableStream } = require ( './utils/stream' )
16
+ const Agent = undici . Agent
16
17
17
18
for ( const factory of [
18
19
( server , opts ) => new undici . Agent ( opts ) ,
19
20
( server , opts ) => new undici . Pool ( `http://${ server } ` , opts ) ,
20
21
( server , opts ) => new undici . Client ( `http://${ server } ` , opts )
21
22
] ) {
22
23
const request = ( t , server , opts , ...args ) => {
23
- const dispatcher = factory ( server , opts )
24
+ opts = opts || { }
25
+ const dispatcher = factory ( server , {
26
+ keepAliveMaxTimeout : 1000 ,
27
+ keepAliveTimeout : 1000 ,
28
+ ...opts
29
+ } )
24
30
t . teardown ( ( ) => dispatcher . close ( ) )
25
31
return undici . request ( args [ 0 ] , { ...args [ 1 ] , dispatcher } , args [ 2 ] )
26
32
}
@@ -371,10 +377,16 @@ t.test('should follow redirections when going cross origin', async t => {
371
377
t . test ( 'should handle errors (callback)' , t => {
372
378
t . plan ( 1 )
373
379
380
+ const agent = new Agent ( {
381
+ keepAliveTimeout : 1000 ,
382
+ keepAliveMaxTimeout : 1000
383
+ } )
384
+
374
385
undici . request (
375
386
'http://localhost:0' ,
376
387
{
377
- maxRedirections : 10
388
+ maxRedirections : 10 ,
389
+ dispatcher : agent
378
390
} ,
379
391
error => {
380
392
t . match ( error . code , / E A D D R N O T A V A I L | E C O N N R E F U S E D / )
@@ -383,18 +395,27 @@ t.test('should handle errors (callback)', t => {
383
395
} )
384
396
385
397
t . test ( 'should handle errors (promise)' , async t => {
398
+ const agent = new Agent ( {
399
+ keepAliveTimeout : 1000 ,
400
+ keepAliveMaxTimeout : 1000
401
+ } )
386
402
try {
387
- await undici . request ( 'http://localhost:0' , { maxRedirections : 10 } )
403
+ await undici . request ( 'http://localhost:0' , { maxRedirections : 10 , dispatcher : agent } )
388
404
t . fail ( 'Did not throw' )
389
405
} catch ( error ) {
390
406
t . match ( error . code , / E A D D R N O T A V A I L | E C O N N R E F U S E D / )
391
407
}
392
408
} )
393
409
394
410
t . test ( 'removes authorization header on third party origin' , async t => {
411
+ const agent = new Agent ( {
412
+ keepAliveTimeout : 1000 ,
413
+ keepAliveMaxTimeout : 1000
414
+ } )
395
415
const [ server1 ] = await startRedirectingWithAuthorization ( t , 'secret' )
396
416
const { body : bodyStream } = await undici . request ( `http://${ server1 } ` , {
397
417
maxRedirections : 10 ,
418
+ dispatcher : agent ,
398
419
headers : {
399
420
authorization : 'secret'
400
421
}
@@ -406,9 +427,14 @@ t.test('removes authorization header on third party origin', async t => {
406
427
} )
407
428
408
429
t . test ( 'removes cookie header on third party origin' , async t => {
430
+ const agent = new Agent ( {
431
+ keepAliveTimeout : 1000 ,
432
+ keepAliveMaxTimeout : 1000
433
+ } )
409
434
const [ server1 ] = await startRedirectingWithCookie ( t , 'a=b' )
410
435
const { body : bodyStream } = await undici . request ( `http://${ server1 } ` , {
411
436
maxRedirections : 10 ,
437
+ dispatcher : agent ,
412
438
headers : {
413
439
cookie : 'a=b'
414
440
}
0 commit comments