diff options
author | Peter Marton <peter@risingstack.com> | 2017-10-19 20:16:02 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-06 15:40:24 +0100 |
commit | a899576c977aef32d85074ac09d511e4590e28d7 (patch) | |
tree | b065bf00d067a3816db31ce0ec88287be6d75afb /lib/_http_server.js | |
parent | 82a73470506111ecc6361b9e0b0bb01f6377a531 (diff) | |
download | android-node-v8-a899576c977aef32d85074ac09d511e4590e28d7.tar.gz android-node-v8-a899576c977aef32d85074ac09d511e4590e28d7.tar.bz2 android-node-v8-a899576c977aef32d85074ac09d511e4590e28d7.zip |
http: add options to http.createServer()
This adds the optional options argument to `http.createServer()`.
It contains two options: the `IncomingMessage` and `ServerReponse`
option.
PR-URL: https://github.com/nodejs/node/pull/15752
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.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 | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js index 496ebf285c..111a8525c4 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -33,6 +33,7 @@ const { continueExpression, chunkExpression, httpSocketSetup, + kIncomingMessage, _checkInvalidHeaderChar: checkInvalidHeaderChar } = require('_http_common'); const { OutgoingMessage } = require('_http_outgoing'); @@ -41,9 +42,12 @@ const { defaultTriggerAsyncIdScope, getOrSetAsyncId } = require('internal/async_hooks'); +const { IncomingMessage } = require('_http_incoming'); const errors = require('internal/errors'); const Buffer = require('buffer').Buffer; +const kServerResponse = Symbol('ServerResponse'); + const STATUS_CODES = { 100: 'Continue', 101: 'Switching Protocols', @@ -263,9 +267,19 @@ function writeHead(statusCode, reason, obj) { // Docs-only deprecated: DEP0063 ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead; +function Server(options, requestListener) { + if (!(this instanceof Server)) return new Server(options, requestListener); + + if (typeof options === 'function') { + requestListener = options; + options = {}; + } else if (options == null || typeof options === 'object') { + options = util._extend({}, options); + } + + this[kIncomingMessage] = options.IncomingMessage || IncomingMessage; + this[kServerResponse] = options.ServerResponse || ServerResponse; -function Server(requestListener) { - if (!(this instanceof Server)) return new Server(requestListener); net.Server.call(this, { allowHalfOpen: true }); if (requestListener) { @@ -587,7 +601,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { } } - var res = new ServerResponse(req); + var res = new server[kServerResponse](req); res._onPendingData = updateOutgoingData.bind(undefined, socket, state); res.shouldKeepAlive = keepAlive; @@ -690,5 +704,6 @@ module.exports = { STATUS_CODES, Server, ServerResponse, - _connectionListener: connectionListener + _connectionListener: connectionListener, + kServerResponse }; |