diff options
author | Brian White <mscdex@mscdex.net> | 2016-12-31 16:18:43 -0500 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2017-01-11 12:54:31 -0500 |
commit | c00e4adbb4c6dd5bfbf22a3efcecb63c56958339 (patch) | |
tree | b18dc321b81c4c054471c577f665f2f27352dd36 /lib/_http_server.js | |
parent | ec8910bcea8d57a1faf07202364cb4f3eee769ac (diff) | |
download | android-node-v8-c00e4adbb4c6dd5bfbf22a3efcecb63c56958339.tar.gz android-node-v8-c00e4adbb4c6dd5bfbf22a3efcecb63c56958339.tar.bz2 android-node-v8-c00e4adbb4c6dd5bfbf22a3efcecb63c56958339.zip |
http: optimize header storage and matching
This commit implements two optimizations when working with headers:
* Avoid having to explicitly "render" headers and separately store the
original casing for header names.
* Match special header names using a single regular expression instead
of testing one regular expression per header name.
PR-URL: https://github.com/nodejs/node/pull/10558
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'lib/_http_server.js')
-rw-r--r-- | lib/_http_server.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js index fe563977a6..d473fd3281 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -161,7 +161,6 @@ ServerResponse.prototype._implicitHeader = function _implicitHeader() { ServerResponse.prototype.writeHead = writeHead; function writeHead(statusCode, reason, obj) { - var headers; statusCode |= 0; if (statusCode < 100 || statusCode > 999) throw new RangeError(`Invalid status code: ${statusCode}`); @@ -177,17 +176,25 @@ function writeHead(statusCode, reason, obj) { } this.statusCode = statusCode; + var headers; if (this._headers) { // Slow-case: when progressive API and header fields are passed. + var k; if (obj) { var keys = Object.keys(obj); for (var i = 0; i < keys.length; i++) { - var k = keys[i]; + k = keys[i]; if (k) this.setHeader(k, obj[k]); } } + if (k === undefined) { + if (this._header) { + throw new Error('Can\'t render headers after they are sent to the ' + + 'client'); + } + } // only progressive api is used - headers = this._renderHeaders(); + headers = this._headers; } else { // only writeHead() called headers = obj; |