From e5f53206dd6559fecab3235aa620ef146c536f64 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 18 Apr 2018 16:39:27 +0200 Subject: [PATCH] http: simplify connection: close search Remove upgrade from the regular expression as it is no longer used and switch to using `.test()` instead of `.match()` as the value matched is irrelevant. PR-URL: https://github.com/nodejs/node/pull/20131 Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Ruben Bridgewater --- lib/_http_outgoing.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 8406c9cd8b0..770e555d1ea 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -52,7 +52,7 @@ const { utcDate } = internalHttp; const kIsCorked = Symbol('isCorked'); -var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig; +var RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i; var RE_TE_CHUNKED = common.chunkExpression; // isCookieField performs a case-insensitive comparison of a provided string @@ -432,20 +432,6 @@ function storeHeader(self, state, key, value, validate) { matchHeader(self, state, key, value); } -function matchConnValue(self, state, value) { - var sawClose = false; - var m = RE_CONN_VALUES.exec(value); - while (m) { - if (m[0].length === 5) - sawClose = true; - m = RE_CONN_VALUES.exec(value); - } - if (sawClose) - self._last = true; - else - self.shouldKeepAlive = true; -} - function matchHeader(self, state, field, value) { if (field.length < 4 || field.length > 17) return; @@ -453,7 +439,10 @@ function matchHeader(self, state, field, value) { switch (field) { case 'connection': state.connection = true; - matchConnValue(self, state, value); + if (RE_CONN_CLOSE.test(value)) + self._last = true; + else + self.shouldKeepAlive = true; break; case 'transfer-encoding': state.te = true;