request: make pool an explicit option.
This commit is contained in:
parent
22c5014c49
commit
aa07255d74
@ -197,6 +197,7 @@ HTTPClient.prototype._request = co(function* _request(method, endpoint, json) {
|
|||||||
res = yield request({
|
res = yield request({
|
||||||
method: method,
|
method: method,
|
||||||
uri: this.uri + endpoint,
|
uri: this.uri + endpoint,
|
||||||
|
pool: true,
|
||||||
query: query,
|
query: query,
|
||||||
json: json,
|
json: json,
|
||||||
auth: {
|
auth: {
|
||||||
|
|||||||
@ -36,6 +36,7 @@ function RequestOptions(options) {
|
|||||||
this.ssl = false;
|
this.ssl = false;
|
||||||
this.method = 'GET';
|
this.method = 'GET';
|
||||||
this.strictSSL = true;
|
this.strictSSL = true;
|
||||||
|
this.pool = false;
|
||||||
this.agent = USER_AGENT;
|
this.agent = USER_AGENT;
|
||||||
|
|
||||||
this.type = null;
|
this.type = null;
|
||||||
@ -106,16 +107,21 @@ RequestOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.method = options.method.toUpperCase();
|
this.method = options.method.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.agent != null) {
|
|
||||||
assert(typeof options.agent === 'string');
|
|
||||||
this.agent = options.agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.strictSSL != null) {
|
if (options.strictSSL != null) {
|
||||||
assert(typeof options.strictSSL === 'boolean');
|
assert(typeof options.strictSSL === 'boolean');
|
||||||
this.strictSSL = options.strictSSL;
|
this.strictSSL = options.strictSSL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.pool != null) {
|
||||||
|
assert(typeof options.pool === 'boolean');
|
||||||
|
this.pool = options.pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.agent != null) {
|
||||||
|
assert(typeof options.agent === 'string');
|
||||||
|
this.agent = options.agent;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.auth != null) {
|
if (options.auth != null) {
|
||||||
assert(typeof options.auth === 'object');
|
assert(typeof options.auth === 'object');
|
||||||
assert(typeof options.auth.username === 'string');
|
assert(typeof options.auth.username === 'string');
|
||||||
@ -225,6 +231,7 @@ RequestOptions.prototype.toHTTP = function toHTTP() {
|
|||||||
port: this.port,
|
port: this.port,
|
||||||
path: this.path + query,
|
path: this.path + query,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
agent: this.pool ? null : false,
|
||||||
rejectUnauthorized: this.strictSSL
|
rejectUnauthorized: this.strictSSL
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -314,13 +321,6 @@ Request.prototype.close = function close() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (this.response.socket) {
|
|
||||||
try {
|
|
||||||
this.response.socket.destroy();
|
|
||||||
} catch (e) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
@ -443,13 +443,6 @@ Request.prototype._onResponse = function _onResponse(response) {
|
|||||||
this.response.on('data', this.onData);
|
this.response.on('data', this.onData);
|
||||||
this.response.on('error', this.onEnd);
|
this.response.on('error', this.onEnd);
|
||||||
this.response.on('end', this.onEnd);
|
this.response.on('end', this.onEnd);
|
||||||
|
|
||||||
if (this.response.socket) {
|
|
||||||
this.response.socket.on('error', this.onEnd);
|
|
||||||
// An agent socket's `end` sometimes
|
|
||||||
// won't be emitted on the response.
|
|
||||||
this.response.socket.on('end', this.onEnd);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Request.prototype._onData = function _onData(data) {
|
Request.prototype._onData = function _onData(data) {
|
||||||
|
|||||||
@ -48,6 +48,7 @@ RPCClient.prototype.call = co(function* call(method, params) {
|
|||||||
var res = yield request.promise({
|
var res = yield request.promise({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
uri: this.uri,
|
uri: this.uri,
|
||||||
|
pool: true,
|
||||||
json: {
|
json: {
|
||||||
method: method,
|
method: method,
|
||||||
params: params,
|
params: params,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user