Skip to content

Commit

Permalink
http: fix permanent deoptimizations
Browse files Browse the repository at this point in the history
PR-URL: #12456
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex committed Apr 30, 2017
1 parent 7a5bac5 commit e283319
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
13 changes: 7 additions & 6 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function ClientRequest(options, cb) {
'Expected "' + expectedProtocol + '"');
}

const defaultPort = options.defaultPort ||
this.agent && this.agent.defaultPort;
var defaultPort = options.defaultPort ||
this.agent && this.agent.defaultPort;

var port = options.port = options.port || defaultPort || 80;
var host = options.host = validateHost(options.hostname, 'hostname') ||
Expand Down Expand Up @@ -226,7 +226,7 @@ function ClientRequest(options, cb) {

var called = false;

const oncreate = (err, socket) => {
var oncreate = (err, socket) => {
if (called)
return;
called = true;
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e283319

Please sign in to comment.