Skip to content

Commit

Permalink
https: align https server options with http options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayase-252 committed Jun 10, 2021
1 parent f7a5d5e commit 2243db8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
28 changes: 16 additions & 12 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -991,6 +994,7 @@ module.exports = {
STATUS_CODES,
Server,
ServerResponse,
storeHTTPOptions,
_connectionListener: connectionListener,
kServerResponse
};
15 changes: 2 additions & 13 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 2243db8

Please sign in to comment.