summaryrefslogtreecommitdiff
path: root/lib/_http_outgoing.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-04-18 15:45:45 +0200
committerAnatoli Papirovski <apapirovski@mac.com>2018-04-22 07:51:38 +0200
commit54caeae38a66841b7f7119649dc78ce55c8a7c52 (patch)
treef13bbe204a25152ac7591994acfbdd0098e3ac77 /lib/_http_outgoing.js
parentdb0174bbc86c86b8e22c37977c88ddced559ad79 (diff)
downloadandroid-node-v8-54caeae38a66841b7f7119649dc78ce55c8a7c52.tar.gz
android-node-v8-54caeae38a66841b7f7119649dc78ce55c8a7c52.tar.bz2
android-node-v8-54caeae38a66841b7f7119649dc78ce55c8a7c52.zip
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>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r--lib/_http_outgoing.js43
1 files changed, 20 insertions, 23 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index 8ed4940196..8406c9cd8b 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -52,8 +52,6 @@ const { utcDate } = internalHttp;
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_TE_CHUNKED = common.chunkExpression;
@@ -449,28 +447,27 @@ function matchConnValue(self, state, value) {
}
function matchHeader(self, state, field, value) {
- var m = RE_FIELDS.exec(field);
- if (!m)
+ if (field.length < 4 || field.length > 17)
return;
- var len = m[0].length;
- if (len === 10) {
- state.connection = true;
- matchConnValue(self, state, value);
- } else if (len === 17) {
- state.te = true;
- if (RE_TE_CHUNKED.test(value)) self.chunkedEncoding = true;
- } else if (len === 14) {
- state.contLen = true;
- } else if (len === 4) {
- state.date = true;
- } else if (len === 6) {
- state.expect = true;
- } else if (len === 7) {
- var ch = m[0].charCodeAt(0);
- if (ch === 85 || ch === 117)
- state.upgrade = true;
- else
- state.trailer = true;
+ field = field.toLowerCase();
+ switch (field) {
+ case 'connection':
+ state.connection = true;
+ matchConnValue(self, state, value);
+ break;
+ case 'transfer-encoding':
+ state.te = true;
+ if (RE_TE_CHUNKED.test(value)) self.chunkedEncoding = true;
+ break;
+ case 'content-length':
+ state.contLen = true;
+ break;
+ case 'date':
+ case 'expect':
+ case 'trailer':
+ case 'upgrade':
+ state[field] = true;
+ break;
}
}