Skip to content

Commit

Permalink
fixup! refactor: split h1 and h2 connect into own methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 25, 2024
1 parent f837eba commit 8c9a737
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class Client extends DispatcherBase {
this[kMaxRequests] = maxRequestsPerClient
this[kClosedResolve] = null
this[kMaxResponseSize] = maxResponseSize > -1 ? maxResponseSize : -1
this[kHTTPConnVersion] = 'h1'
this[kHTTPConnVersion] = null

// HTTP/2
this[kHTTP2Session] = null
Expand Down Expand Up @@ -1177,9 +1177,9 @@ async function connect (client) {
assert(socket)

if (socket.alpnProtocol === 'h2') {
await onHTTP2Connect(client, socket)
await connectH2(client, socket)
} else {
await onHTTP1Connect(client, socket)
await connectH1(client, socket)
}

addListener(socket, 'close', onSocketClose)
Expand Down Expand Up @@ -2271,7 +2271,9 @@ function errorRequest (client, request, err) {
}
}

async function onHTTP1Connect (client, socket) {
async function connectH1 (client, socket) {
client[kHTTPConnVersion] = 'h1'

if (!llhttpInstance) {
llhttpInstance = await llhttpPromise
llhttpPromise = null
Expand Down Expand Up @@ -2332,7 +2334,9 @@ async function onHTTP1Connect (client, socket) {
})
}

async function onHTTP2Connect (client, socket) {
async function connectH2 (client, socket) {
client[kHTTPConnVersion] = 'h2'

if (!h2ExperimentalWarned) {
h2ExperimentalWarned = true
process.emitWarning('H2 support is experimental, expect them to change at any time.', {
Expand All @@ -2345,7 +2349,6 @@ async function onHTTP2Connect (client, socket) {
peerMaxConcurrentStreams: client[kHTTP2SessionState].maxConcurrentStreams
})

client[kHTTPConnVersion] = 'h2'
session[kClient] = client
session[kSocket] = socket
session.on('error', onHttp2SessionError)
Expand Down

0 comments on commit 8c9a737

Please sign in to comment.