Skip to content

Commit 2883454

Browse files
apapirovskijasnell
authored andcommitted
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: #20131 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 4fe1b60 commit 2883454

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

lib/_http_outgoing.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const { utcDate } = internalHttp;
5252

5353
const kIsCorked = Symbol('isCorked');
5454

55-
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
55+
var RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
5656
var RE_TE_CHUNKED = common.chunkExpression;
5757

5858
// isCookieField performs a case-insensitive comparison of a provided string
@@ -432,28 +432,17 @@ function storeHeader(self, state, key, value, validate) {
432432
matchHeader(self, state, key, value);
433433
}
434434

435-
function matchConnValue(self, state, value) {
436-
var sawClose = false;
437-
var m = RE_CONN_VALUES.exec(value);
438-
while (m) {
439-
if (m[0].length === 5)
440-
sawClose = true;
441-
m = RE_CONN_VALUES.exec(value);
442-
}
443-
if (sawClose)
444-
self._last = true;
445-
else
446-
self.shouldKeepAlive = true;
447-
}
448-
449435
function matchHeader(self, state, field, value) {
450436
if (field.length < 4 || field.length > 17)
451437
return;
452438
field = field.toLowerCase();
453439
switch (field) {
454440
case 'connection':
455441
state.connection = true;
456-
matchConnValue(self, state, value);
442+
if (RE_CONN_CLOSE.test(value))
443+
self._last = true;
444+
else
445+
self.shouldKeepAlive = true;
457446
break;
458447
case 'transfer-encoding':
459448
state.te = true;

0 commit comments

Comments
 (0)