@@ -1290,6 +1290,48 @@ test('ProxyAgent keeps customized host in request headers - #3019', async (t) =>
12901290 proxyAgent . close ( )
12911291} )
12921292
1293+ test ( 'ProxyAgent handles multiple concurrent HTTP requests via HTTP proxy' , async ( t ) => {
1294+ t = tspl ( t , { plan : 20 } )
1295+ // Start target HTTP server
1296+ const server = createServer ( ( req , res ) => {
1297+ setTimeout ( ( ) => {
1298+ res . setHeader ( 'content-type' , 'application/json' )
1299+ res . end ( JSON . stringify ( { url : req . url } ) )
1300+ } , 50 )
1301+ } )
1302+ await new Promise ( resolve => server . listen ( 0 , resolve ) )
1303+ const targetPort = server . address ( ) . port
1304+
1305+ // Start HTTP proxy server
1306+ const proxy = createProxy ( createServer ( ) )
1307+ await new Promise ( resolve => proxy . listen ( 0 , resolve ) )
1308+ const proxyPort = proxy . address ( ) . port
1309+
1310+ // Create ProxyAgent (no tunneling, plain HTTP)
1311+ const proxyAgent = new ProxyAgent ( `http://localhost:${ proxyPort } ` )
1312+
1313+ const N = 10
1314+ const requests = [ ]
1315+ for ( let i = 0 ; i < N ; i ++ ) {
1316+ requests . push (
1317+ request ( `http://localhost:${ targetPort } /test${ i } ` , { dispatcher : proxyAgent } )
1318+ . then ( async res => {
1319+ t . strictEqual ( res . statusCode , 200 )
1320+ const json = await res . body . json ( )
1321+ t . deepStrictEqual ( json , { url : `/test${ i } ` } )
1322+ } )
1323+ )
1324+ }
1325+ try {
1326+ await Promise . all ( requests )
1327+ } catch ( err ) {
1328+ t . fail ( err )
1329+ }
1330+ server . close ( )
1331+ proxy . close ( )
1332+ proxyAgent . close ( )
1333+ } )
1334+
12931335function buildServer ( ) {
12941336 return new Promise ( ( resolve ) => {
12951337 const server = createServer ( { joinDuplicateHeaders : true } )
0 commit comments