Skip to content

Commit

Permalink
http: simplify connection: close search
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
apapirovski authored and jasnell committed Apr 23, 2018
1 parent 4fe1b60 commit 2883454
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -432,28 +432,17 @@ 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;
field = field.toLowerCase();
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;
Expand Down

0 comments on commit 2883454

Please sign in to comment.