http: use switch in matchHeader
Using a switch improves clarity of the code but also performance for all but a few edge cases which remain on par with the old code. 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:
parent
db0174bbc8
commit
54caeae38a
@ -52,8 +52,6 @@ const { utcDate } = internalHttp;
|
|||||||
|
|
||||||
const kIsCorked = Symbol('isCorked');
|
const kIsCorked = Symbol('isCorked');
|
||||||
|
|
||||||
var RE_FIELDS =
|
|
||||||
/^(?:Connection|Transfer-Encoding|Content-Length|Date|Expect|Trailer|Upgrade)$/i;
|
|
||||||
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
|
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
|
||||||
var RE_TE_CHUNKED = common.chunkExpression;
|
var RE_TE_CHUNKED = common.chunkExpression;
|
||||||
|
|
||||||
@ -449,28 +447,27 @@ function matchConnValue(self, state, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function matchHeader(self, state, field, value) {
|
function matchHeader(self, state, field, value) {
|
||||||
var m = RE_FIELDS.exec(field);
|
if (field.length < 4 || field.length > 17)
|
||||||
if (!m)
|
|
||||||
return;
|
return;
|
||||||
var len = m[0].length;
|
field = field.toLowerCase();
|
||||||
if (len === 10) {
|
switch (field) {
|
||||||
state.connection = true;
|
case 'connection':
|
||||||
matchConnValue(self, state, value);
|
state.connection = true;
|
||||||
} else if (len === 17) {
|
matchConnValue(self, state, value);
|
||||||
state.te = true;
|
break;
|
||||||
if (RE_TE_CHUNKED.test(value)) self.chunkedEncoding = true;
|
case 'transfer-encoding':
|
||||||
} else if (len === 14) {
|
state.te = true;
|
||||||
state.contLen = true;
|
if (RE_TE_CHUNKED.test(value)) self.chunkedEncoding = true;
|
||||||
} else if (len === 4) {
|
break;
|
||||||
state.date = true;
|
case 'content-length':
|
||||||
} else if (len === 6) {
|
state.contLen = true;
|
||||||
state.expect = true;
|
break;
|
||||||
} else if (len === 7) {
|
case 'date':
|
||||||
var ch = m[0].charCodeAt(0);
|
case 'expect':
|
||||||
if (ch === 85 || ch === 117)
|
case 'trailer':
|
||||||
state.upgrade = true;
|
case 'upgrade':
|
||||||
else
|
state[field] = true;
|
||||||
state.trailer = true;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user