From 798abca684a0584f6ec0cd7fa9ef0c2c5ef2be47 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 5 Sep 2020 16:45:53 +0200 Subject: [PATCH] perf: slightly faster keep alive header parsing (#401) --- lib/core/client.js | 2 +- lib/core/util.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/client.js b/lib/core/client.js index 587c4408121..4eb86c1eff2 100644 --- a/lib/core/client.js +++ b/lib/core/client.js @@ -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] diff --git a/lib/core/util.js b/lib/core/util.js index 00348a35080..30ff7f2d13e 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -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 } } }