http: add options to http.createServer()

This adds the optional options argument to `http.createServer()`.
It contains two options: the `IncomingMessage` and `ServerReponse`
option.

Backport-PR-URL: https://github.com/nodejs/node/pull/20456
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>
This commit is contained in:
Peter Marton authored and Rod Vagg committed 2018-08-16 11:38:47 +10:00
1 parent 0cae3c3fe5
commit 01dc646382
9 files changed
+222 -10

No files matched your search

+6 -2
View File
@@ -30,6 +30,9 @@ const util = require('util');
const { inherits } = util;
const debug = util.debuglog('https');
const { urlToOptions, searchParamsSymbol } = require('internal/url');
const { IncomingMessage, ServerResponse } = require('http');
const { kIncomingMessage } = require('_http_common');
const { kServerResponse } = require('_http_server');
function Server(opts, requestListener) {
if (!(this instanceof Server)) return new Server(opts, requestListener);
@@ -51,9 +54,10 @@ function Server(opts, requestListener) {
opts.ALPNProtocols = ['http/1.1'];
}
tls.Server.call(this, opts, http._connectionListener);
this[kIncomingMessage] = opts.IncomingMessage || IncomingMessage;
this[kServerResponse] = opts.ServerResponse || ServerResponse;
this.httpAllowHalfOpen = false;
tls.Server.call(this, opts, http._connectionListener);
if (requestListener) {
this.addListener('request', requestListener);