http: fix permanent deoptimizations

PR-URL: https://github.com/nodejs/node/pull/12456
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Brian White 2017-04-24 02:19:30 -04:00
parent 7a5bac5d36
commit e283319969
No known key found for this signature in database
GPG Key ID: 606D7358F94DA209
2 changed files with 11 additions and 9 deletions

View File

@ -130,13 +130,14 @@ Agent.prototype.getName = function getName(options) {
return name;
};
Agent.prototype.addRequest = function addRequest(req, options) {
Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/,
localAddress/*legacy*/) {
// Legacy API: addRequest(req, host, port, localAddress)
if (typeof options === 'string') {
options = {
host: options,
port: arguments[2],
localAddress: arguments[3]
port,
localAddress
};
}

View File

@ -127,7 +127,7 @@ function ClientRequest(options, cb) {
'Expected "' + expectedProtocol + '"');
}
const defaultPort = options.defaultPort ||
var defaultPort = options.defaultPort ||
this.agent && this.agent.defaultPort;
var port = options.port = options.port || defaultPort || 80;
@ -226,7 +226,7 @@ function ClientRequest(options, cb) {
var called = false;
const oncreate = (err, socket) => {
var oncreate = (err, socket) => {
if (called)
return;
called = true;
@ -238,14 +238,15 @@ function ClientRequest(options, cb) {
this._deferToConnect(null, null, () => this._flush());
};
var newSocket;
if (this.socketPath) {
this._last = true;
this.shouldKeepAlive = false;
const optionsPath = {
var optionsPath = {
path: this.socketPath,
timeout: this.timeout
};
const newSocket = this.agent.createConnection(optionsPath, oncreate);
newSocket = this.agent.createConnection(optionsPath, oncreate);
if (newSocket && !called) {
called = true;
this.onSocket(newSocket);
@ -270,7 +271,7 @@ function ClientRequest(options, cb) {
this._last = true;
this.shouldKeepAlive = false;
if (typeof options.createConnection === 'function') {
const newSocket = options.createConnection(options, oncreate);
newSocket = options.createConnection(options, oncreate);
if (newSocket && !called) {
called = true;
this.onSocket(newSocket);