Skip to content

Commit

Permalink
refactor: keep alive parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 19, 2020
1 parent 36b9bfb commit 691feb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
30 changes: 15 additions & 15 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,28 +530,28 @@ class Parser extends HTTPParser {
return 2
}

if (!shouldKeepAlive) {
// Stop more requests from being dispatched.
client[kReset] = true
}

const { headers } = this
this.headers = null

let keepAliveTimeout = util.parseKeepAliveTimeout(shouldKeepAlive, headers)
if (shouldKeepAlive) {
let keepAliveTimeout = util.parseKeepAliveTimeout(headers)

if (Number.isFinite(keepAliveTimeout)) {
keepAliveTimeout = Math.min(
keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
client[kMaxKeepAliveTimeout]
)
if (keepAliveTimeout < 1e3) {
client[kReset] = true
if (Number.isFinite(keepAliveTimeout)) {
keepAliveTimeout = Math.min(
keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
client[kMaxKeepAliveTimeout]
)
if (keepAliveTimeout < 1e3) {
client[kReset] = true
} else {
client[kKeepAliveTimeout] = keepAliveTimeout
}
} else {
client[kKeepAliveTimeout] = keepAliveTimeout
client[kKeepAliveTimeout] = client[kIdleTimeout]
}
} else {
client[kKeepAliveTimeout] = client[kIdleTimeout]
// Stop more requests from being dispatched.
client[kReset] = true
}

request.onHeaders(statusCode, headers, statusCode < 200 ? null : socket[kResume])
Expand Down
6 changes: 1 addition & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ function destroy (stream, err) {
}
}

function parseKeepAliveTimeout (shouldKeepAlive, headers) {
if (!shouldKeepAlive) {
return null
}

function parseKeepAliveTimeout (headers) {
let keepAliveHeader
for (let n = 0; n < headers.length; n += 2) {
const key = headers[n + 0]
Expand Down

0 comments on commit 691feb2

Please sign in to comment.