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:
parent
7a5bac5d36
commit
e283319969
@ -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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user