Skip to content

Commit 8c9a737

Browse files
committed
fixup! refactor: split h1 and h2 connect into own methods
1 parent f837eba commit 8c9a737

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/dispatcher/client.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class Client extends DispatcherBase {
291291
this[kMaxRequests] = maxRequestsPerClient
292292
this[kClosedResolve] = null
293293
this[kMaxResponseSize] = maxResponseSize > -1 ? maxResponseSize : -1
294-
this[kHTTPConnVersion] = 'h1'
294+
this[kHTTPConnVersion] = null
295295

296296
// HTTP/2
297297
this[kHTTP2Session] = null
@@ -1177,9 +1177,9 @@ async function connect (client) {
11771177
assert(socket)
11781178

11791179
if (socket.alpnProtocol === 'h2') {
1180-
await onHTTP2Connect(client, socket)
1180+
await connectH2(client, socket)
11811181
} else {
1182-
await onHTTP1Connect(client, socket)
1182+
await connectH1(client, socket)
11831183
}
11841184

11851185
addListener(socket, 'close', onSocketClose)
@@ -2271,7 +2271,9 @@ function errorRequest (client, request, err) {
22712271
}
22722272
}
22732273

2274-
async function onHTTP1Connect (client, socket) {
2274+
async function connectH1 (client, socket) {
2275+
client[kHTTPConnVersion] = 'h1'
2276+
22752277
if (!llhttpInstance) {
22762278
llhttpInstance = await llhttpPromise
22772279
llhttpPromise = null
@@ -2332,7 +2334,9 @@ async function onHTTP1Connect (client, socket) {
23322334
})
23332335
}
23342336

2335-
async function onHTTP2Connect (client, socket) {
2337+
async function connectH2 (client, socket) {
2338+
client[kHTTPConnVersion] = 'h2'
2339+
23362340
if (!h2ExperimentalWarned) {
23372341
h2ExperimentalWarned = true
23382342
process.emitWarning('H2 support is experimental, expect them to change at any time.', {
@@ -2345,7 +2349,6 @@ async function onHTTP2Connect (client, socket) {
23452349
peerMaxConcurrentStreams: client[kHTTP2SessionState].maxConcurrentStreams
23462350
})
23472351

2348-
client[kHTTPConnVersion] = 'h2'
23492352
session[kClient] = client
23502353
session[kSocket] = socket
23512354
session.on('error', onHttp2SessionError)

0 commit comments

Comments
 (0)