Skip to content

Commit 5334fa6

Browse files
authored
fix: preserve connect option in H2CClient (#5000)
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
1 parent 743aa89 commit 5334fa6

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/dispatcher/h2c-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class H2CClient extends Client {
1515
)
1616
}
1717

18-
const { connect, maxConcurrentStreams, pipelining, ...opts } =
18+
const { maxConcurrentStreams, pipelining, ...opts } =
1919
clientOpts ?? {}
2020
let defaultMaxConcurrentStreams = 100
2121
let defaultPipelining = 100

test/h2c-client.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ test('Connect to h2c server over a unix domain socket', { skip: process.platform
140140
})
141141
})
142142

143+
test('Should pass custom connect function to Client', async t => {
144+
const planner = tspl(t, { plan: 3 })
145+
146+
const connectError = new Error('custom connect error')
147+
const socketPath = '/var/run/test.sock'
148+
const client = new H2CClient('http://localhost', {
149+
socketPath,
150+
connect (opts, cb) {
151+
planner.strictEqual(opts.socketPath, socketPath)
152+
planner.strictEqual(opts.allowH2, true)
153+
cb(connectError, null)
154+
}
155+
})
156+
157+
t.after(() => client.close())
158+
159+
client.request({
160+
path: '/',
161+
method: 'GET'
162+
}, (err) => {
163+
planner.strictEqual(err, connectError)
164+
})
165+
166+
await planner.completed
167+
})
168+
143169
test('Should throw if bad useH2c has been passed', async t => {
144170
t = tspl(t, { plan: 1 })
145171

0 commit comments

Comments
 (0)