Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https: refactor to use more primordials #36195

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 20 additions & 13 deletions lib/https.js
Expand Up @@ -22,9 +22,16 @@
'use strict';

const {
ArrayPrototypeIndexOf,
ArrayPrototypePush,
ArrayPrototypeShift,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
FunctionPrototypeCall,
JSONStringify,
ObjectAssign,
ObjectSetPrototypeOf,
JSONStringify,
ReflectConstruct,
} = primordials;

require('internal/util').assertCrypto();
Expand Down Expand Up @@ -64,7 +71,7 @@ function Server(opts, requestListener) {
this[kIncomingMessage] = opts.IncomingMessage || IncomingMessage;
this[kServerResponse] = opts.ServerResponse || ServerResponse;

tls.Server.call(this, opts, _connectionListener);
FunctionPrototypeCall(tls.Server, this, opts, _connectionListener);

this.httpAllowHalfOpen = false;

Expand Down Expand Up @@ -150,7 +157,7 @@ function Agent(options) {
if (!(this instanceof Agent))
return new Agent(options);

HttpAgent.call(this, options);
FunctionPrototypeCall(HttpAgent, this, options);
this.defaultPort = 443;
this.protocol = 'https:';
this.maxCachedSessions = this.options.maxCachedSessions;
Expand All @@ -167,7 +174,7 @@ ObjectSetPrototypeOf(Agent, HttpAgent);
Agent.prototype.createConnection = createConnection;

Agent.prototype.getName = function getName(options) {
let name = HttpAgent.prototype.getName.call(this, options);
let name = FunctionPrototypeCall(HttpAgent.prototype.getName, this, options);

name += ':';
if (options.ca)
Expand Down Expand Up @@ -269,21 +276,21 @@ Agent.prototype._cacheSession = function _cacheSession(key, session) {

// Put new entry
if (this._sessionCache.list.length >= this.maxCachedSessions) {
const oldKey = this._sessionCache.list.shift();
const oldKey = ArrayPrototypeShift(this._sessionCache.list);
debug('evicting %j', oldKey);
delete this._sessionCache.map[oldKey];
}

this._sessionCache.list.push(key);
ArrayPrototypePush(this._sessionCache.list, key);
this._sessionCache.map[key] = session;
};

Agent.prototype._evictSession = function _evictSession(key) {
const index = this._sessionCache.list.indexOf(key);
const index = ArrayPrototypeIndexOf(this._sessionCache.list, key);
if (index === -1)
return;

this._sessionCache.list.splice(index, 1);
ArrayPrototypeSplice(this._sessionCache.list, index, 1);
delete this._sessionCache.map[key];
};

Expand All @@ -294,7 +301,7 @@ function request(...args) {
let options = {};

if (typeof args[0] === 'string') {
const urlStr = args.shift();
const urlStr = ArrayPrototypeShift(args);
try {
options = urlToOptions(new URL(urlStr));
} catch (err) {
Expand All @@ -313,17 +320,17 @@ function request(...args) {
} else if (args[0] && args[0][searchParamsSymbol] &&
args[0][searchParamsSymbol][searchParamsSymbol]) {
// url.URL instance
options = urlToOptions(args.shift());
options = urlToOptions(ArrayPrototypeShift(args));
}

if (args[0] && typeof args[0] !== 'function') {
ObjectAssign(options, args.shift());
ObjectAssign(options, ArrayPrototypeShift(args));
}

options._defaultAgent = module.exports.globalAgent;
args.unshift(options);
ArrayPrototypeUnshift(args, options);

return new ClientRequest(...args);
return ReflectConstruct(ClientRequest, args);
}

function get(input, options, cb) {
Expand Down