request: make pool an explicit option.

This commit is contained in:
Christopher Jeffrey 2016-12-19 07:29:43 -08:00
parent 22c5014c49
commit aa07255d74
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 14 additions and 19 deletions

View File

@ -197,6 +197,7 @@ HTTPClient.prototype._request = co(function* _request(method, endpoint, json) {
res = yield request({
method: method,
uri: this.uri + endpoint,
pool: true,
query: query,
json: json,
auth: {

View File

@ -36,6 +36,7 @@ function RequestOptions(options) {
this.ssl = false;
this.method = 'GET';
this.strictSSL = true;
this.pool = false;
this.agent = USER_AGENT;
this.type = null;
@ -106,16 +107,21 @@ RequestOptions.prototype.fromOptions = function fromOptions(options) {
this.method = options.method.toUpperCase();
}
if (options.agent != null) {
assert(typeof options.agent === 'string');
this.agent = options.agent;
}
if (options.strictSSL != null) {
assert(typeof options.strictSSL === 'boolean');
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) {
assert(typeof options.auth === 'object');
assert(typeof options.auth.username === 'string');
@ -225,6 +231,7 @@ RequestOptions.prototype.toHTTP = function toHTTP() {
port: this.port,
path: this.path + query,
headers: headers,
agent: this.pool ? null : false,
rejectUnauthorized: this.strictSSL
};
};
@ -314,13 +321,6 @@ Request.prototype.close = function close() {
} catch (e) {
;
}
if (this.response.socket) {
try {
this.response.socket.destroy();
} catch (e) {
;
}
}
}
this.cleanup();
@ -443,13 +443,6 @@ Request.prototype._onResponse = function _onResponse(response) {
this.response.on('data', this.onData);
this.response.on('error', 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) {

View File

@ -48,6 +48,7 @@ RPCClient.prototype.call = co(function* call(method, params) {
var res = yield request.promise({
method: 'POST',
uri: this.uri,
pool: true,
json: {
method: method,
params: params,