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; 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) // Legacy API: addRequest(req, host, port, localAddress)
if (typeof options === 'string') { if (typeof options === 'string') {
options = { options = {
host: options, host: options,
port: arguments[2], port,
localAddress: arguments[3] localAddress
}; };
} }

View File

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