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 <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>
This commit is contained in:
Anatoli Papirovski 2018-04-18 16:39:27 +02:00 коммит произвёл James M Snell
Родитель 4fe1b60c5d
Коммит 28834542c8
1 изменённых файлов: 5 добавлений и 16 удалений

Просмотреть файл

@ -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;