Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/dispatcher/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Pool extends PoolBase {
autoSelectFamily,
autoSelectFamilyAttemptTimeout,
allowH2,
useH2c,
clientTtl,
...options
} = {}) {
Expand All @@ -56,6 +57,7 @@ class Pool extends PoolBase {
...tls,
maxCachedSessions,
allowH2,
useH2c,
socketPath,
timeout: connectTimeout,
...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
Expand All @@ -67,7 +69,7 @@ class Pool extends PoolBase {

this[kConnections] = connections || null
this[kUrl] = util.parseOrigin(origin)
this[kOptions] = { ...util.deepClone(options), connect, allowH2, clientTtl, socketPath }
this[kOptions] = { ...util.deepClone(options), connect, allowH2, useH2c, clientTtl, socketPath }
this[kFactory] = factory

this.on('connect', (origin, targets) => {
Expand Down
62 changes: 61 additions & 1 deletion test/h2c-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { test } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')
const pem = require('@metcoder95/https-pem')

const { H2CClient, Client } = require('..')
const { H2CClient, Client, Agent, Pool, request } = require('..')

test('Should throw if no h2c origin', async t => {
const planner = tspl(t, { plan: 1 })
Expand Down Expand Up @@ -180,3 +180,63 @@ test('Should throw if bad useH2c has been passed', async t => {

await t.completed
})

test('Pool with useH2c and connections > 1 should not raise HTTPParserError', async t => {
const planner = tspl(t, { plan: 6 })

const server = createServer((req, res) => {
res.writeHead(200)
res.end('Hello, world!')
})

server.listen(0)
await once(server, 'listening')
const url = `http://localhost:${server.address().port}`
const pool = new Pool(url, { useH2c: true, connections: 2 })

t.after(() => pool.close())
t.after(() => server.close())

const responses = await Promise.all([
pool.request({ path: '/test1', method: 'GET' }),
pool.request({ path: '/test2', method: 'GET' }),
pool.request({ path: '/test3', method: 'GET' })
])

for (const response of responses) {
planner.equal(response.statusCode, 200)
planner.equal(await response.body.text(), 'Hello, world!')
}

await planner.completed
})

test('Agent with useH2c and connections > 1 should not raise HTTPParserError', async t => {
const planner = tspl(t, { plan: 6 })

const server = createServer((req, res) => {
res.writeHead(200)
res.end('Hello, world!')
})

server.listen(0)
await once(server, 'listening')
const port = server.address().port
const agent = new Agent({ useH2c: true, connections: 2 })

t.after(() => agent.close())
t.after(() => server.close())

const responses = await Promise.all([
request(`http://localhost:${port}/test1`, { dispatcher: agent }),
request(`http://localhost:${port}/test2`, { dispatcher: agent }),
request(`http://localhost:${port}/test3`, { dispatcher: agent })
])

for (const response of responses) {
planner.equal(response.statusCode, 200)
planner.equal(await response.body.text(), 'Hello, world!')
}

await planner.completed
})
Loading