diff --git a/lib/_http_server.js b/lib/_http_server.js index 97df58a007daba..11119169d56f2c 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -353,18 +353,7 @@ 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 = { ...options }; - } else { - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); - } - +function storeHTTPOptions(options) { this[kIncomingMessage] = options.IncomingMessage || IncomingMessage; this[kServerResponse] = options.ServerResponse || ServerResponse; @@ -377,7 +366,21 @@ function Server(options, requestListener) { if (insecureHTTPParser !== undefined) validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser'); this.insecureHTTPParser = insecureHTTPParser; +} + +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 = { ...options }; + } else { + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + } + storeHTTPOptions.call(this, options); net.Server.call(this, { allowHalfOpen: true }); if (requestListener) { @@ -991,6 +994,7 @@ module.exports = { STATUS_CODES, Server, ServerResponse, + storeHTTPOptions, _connectionListener: connectionListener, kServerResponse }; diff --git a/lib/https.js b/lib/https.js index 408569b78559c3..695a9020994852 100644 --- a/lib/https.js +++ b/lib/https.js @@ -40,17 +40,14 @@ const tls = require('tls'); const { Agent: HttpAgent } = require('_http_agent'); const { Server: HttpServer, + storeHTTPOptions, _connectionListener, - kServerResponse } = require('_http_server'); const { ClientRequest } = require('_http_client'); let debug = require('internal/util/debuglog').debuglog('https', (fn) => { debug = fn; }); const { URL, urlToHttpOptions, searchParamsSymbol } = require('internal/url'); -const { IncomingMessage, ServerResponse } = require('http'); -const { kIncomingMessage } = require('_http_common'); -const { validateInteger } = require('internal/validators'); function Server(opts, requestListener) { if (!(this instanceof Server)) return new Server(opts, requestListener); @@ -68,15 +65,7 @@ function Server(opts, requestListener) { opts.ALPNProtocols = ['http/1.1']; } - this.maxHeaderSize = 0; - if (opts.maxHeaderSize !== undefined) { - validateInteger(opts.maxHeaderSize, 'maxHeaderSize', 0); - this.maxHeaderSize = opts.maxHeaderSize; - } - - this[kIncomingMessage] = opts.IncomingMessage || IncomingMessage; - this[kServerResponse] = opts.ServerResponse || ServerResponse; - + FunctionPrototypeCall(storeHTTPOptions, this, opts); FunctionPrototypeCall(tls.Server, this, opts, _connectionListener); this.httpAllowHalfOpen = false;