Skip to content

Commit

Permalink
perf: slightly faster keep alive header parsing (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Sep 5, 2020
1 parent d454d01 commit 798abca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class Parser extends HTTPParser {
if (shouldKeepAlive && client[kKeepAlive]) {
const keepAliveTimeout = util.parseKeepAliveTimeout(headers)

if (Number.isFinite(keepAliveTimeout)) {
if (keepAliveTimeout != null) {
const timeout = Math.min(
keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
client[kKeepAliveMaxTimeout]
Expand Down
4 changes: 2 additions & 2 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function parseKeepAliveTimeout (headers) {
for (let n = 0; n < headers.length; n += 2) {
const key = headers[n + 0]
if (key.length === 10 && key.toLowerCase() === 'keep-alive') {
const m = headers[n + 1].match(/timeout=(\d+)/)
return m ? Number(m[1]) * 1000 : undefined
const timeout = parseInt(headers[n + 1].split('timeout=', 2)[1])
return timeout ? timeout * 1000 : undefined
}
}
}
Expand Down

0 comments on commit 798abca

Please # to comment.