@@ -7,7 +7,7 @@ const { test } = require('node:test')
77const { tspl } = require ( '@matteo.collina/tspl' )
88const pem = require ( '@metcoder95/https-pem' )
99
10- const { H2CClient, Client } = require ( '..' )
10+ const { H2CClient, Client, Agent , Pool , request } = require ( '..' )
1111
1212test ( 'Should throw if no h2c origin' , async t => {
1313 const planner = tspl ( t , { plan : 1 } )
@@ -180,3 +180,63 @@ test('Should throw if bad useH2c has been passed', async t => {
180180
181181 await t . completed
182182} )
183+
184+ test ( 'Pool with useH2c and connections > 1 should not raise HTTPParserError' , async t => {
185+ const planner = tspl ( t , { plan : 6 } )
186+
187+ const server = createServer ( ( req , res ) => {
188+ res . writeHead ( 200 )
189+ res . end ( 'Hello, world!' )
190+ } )
191+
192+ server . listen ( 0 )
193+ await once ( server , 'listening' )
194+ const url = `http://localhost:${ server . address ( ) . port } `
195+ const pool = new Pool ( url , { useH2c : true , connections : 2 } )
196+
197+ t . after ( ( ) => pool . close ( ) )
198+ t . after ( ( ) => server . close ( ) )
199+
200+ const responses = await Promise . all ( [
201+ pool . request ( { path : '/test1' , method : 'GET' } ) ,
202+ pool . request ( { path : '/test2' , method : 'GET' } ) ,
203+ pool . request ( { path : '/test3' , method : 'GET' } )
204+ ] )
205+
206+ for ( const response of responses ) {
207+ planner . equal ( response . statusCode , 200 )
208+ planner . equal ( await response . body . text ( ) , 'Hello, world!' )
209+ }
210+
211+ await planner . completed
212+ } )
213+
214+ test ( 'Agent with useH2c and connections > 1 should not raise HTTPParserError' , async t => {
215+ const planner = tspl ( t , { plan : 6 } )
216+
217+ const server = createServer ( ( req , res ) => {
218+ res . writeHead ( 200 )
219+ res . end ( 'Hello, world!' )
220+ } )
221+
222+ server . listen ( 0 )
223+ await once ( server , 'listening' )
224+ const port = server . address ( ) . port
225+ const agent = new Agent ( { useH2c : true , connections : 2 } )
226+
227+ t . after ( ( ) => agent . close ( ) )
228+ t . after ( ( ) => server . close ( ) )
229+
230+ const responses = await Promise . all ( [
231+ request ( `http://localhost:${ port } /test1` , { dispatcher : agent } ) ,
232+ request ( `http://localhost:${ port } /test2` , { dispatcher : agent } ) ,
233+ request ( `http://localhost:${ port } /test3` , { dispatcher : agent } )
234+ ] )
235+
236+ for ( const response of responses ) {
237+ planner . equal ( response . statusCode , 200 )
238+ planner . equal ( await response . body . text ( ) , 'Hello, world!' )
239+ }
240+
241+ await planner . completed
242+ } )
0 commit comments