Skip to content

Commit 3b1b2ed

Browse files
committed
Allow passing agents directly.
1 parent ef86e17 commit 3b1b2ed

File tree

9 files changed

+21
-24
lines changed

9 files changed

+21
-24
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ The type annotations in this documentation generally follow the definitions used
8585
* *databaseName* (optional): name of the active database. Default: `_system`.
8686
* *arangoVersion* (optional): value of the `x-arango-version` header. Default: `20300`.
8787
* *headers* (optional): an object with headers to send with every request.
88-
* *agentOptions* (optional): an object with options for the underlying [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options). This has no effect in the browser. Default: `{maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000}`.
88+
* *agent* (optional): an http Agent instance to use for connections. This has no effect in the browser. Default: a new [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options) instance configured with the *agentOptions*.
89+
* *agentOptions* (optional): an object with options for the agent. This will be ignored if *agent* is also provided and has no effect in the browser. Default: `{maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000}`.
8990

9091
If *config* is a string, it will be interpreted as *config.url*.
9192

dist/arango.all.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ function Connection(config) {
603603
if (!this.config.headers['x-arango-version']) {
604604
this.config.headers['x-arango-version'] = this.config.arangoVersion;
605605
}
606-
this._request = createRequest(this.config.agentOptions);
606+
this._request = createRequest(this.config.agent, this.config.agentOptions);
607607
}
608608

609609
Connection.defaults = {
@@ -1812,9 +1812,8 @@ var parseUrl = require('url').parse;
18121812
var extend = require('extend');
18131813
var once = require('./once');
18141814

1815-
module.exports = function (agentOptions) {
1816-
var agent;
1817-
if (http.Agent) agent = new http.Agent(agentOptions); // server only
1815+
module.exports = function (agent, agentOptions) {
1816+
if (!agent && http.Agent) agent = new http.Agent(agentOptions); // server only
18181817
return function request(_ref, cb) {
18191818
var method = _ref.method;
18201819
var url = _ref.url;

dist/arango.all.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/arango.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ function Connection(config) {
603603
if (!this.config.headers['x-arango-version']) {
604604
this.config.headers['x-arango-version'] = this.config.arangoVersion;
605605
}
606-
this._request = createRequest(this.config.agentOptions);
606+
this._request = createRequest(this.config.agent, this.config.agentOptions);
607607
}
608608

609609
Connection.defaults = {
@@ -1812,9 +1812,8 @@ var parseUrl = require('url').parse;
18121812
var extend = require('extend');
18131813
var once = require('./once');
18141814

1815-
module.exports = function (agentOptions) {
1816-
var agent;
1817-
if (http.Agent) agent = new http.Agent(agentOptions); // server only
1815+
module.exports = function (agent, agentOptions) {
1816+
if (!agent && http.Agent) agent = new http.Agent(agentOptions); // server only
18181817
return function request(_ref, cb) {
18191818
var method = _ref.method;
18201819
var url = _ref.url;

dist/arango.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Connection(config) {
1919
if (!this.config.headers['x-arango-version']) {
2020
this.config.headers['x-arango-version'] = this.config.arangoVersion;
2121
}
22-
this._request = createRequest(this.config.agentOptions);
22+
this._request = createRequest(this.config.agent, this.config.agentOptions);
2323
}
2424

2525
Connection.defaults = {

lib/util/request.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ var parseUrl = require('url').parse;
44
var extend = require('extend');
55
var once = require('./once');
66

7-
module.exports = function (agentOptions) {
8-
var agent;
9-
if (http.Agent) agent = new http.Agent(agentOptions); // server only
7+
module.exports = function (agent, agentOptions) {
8+
if (!agent && http.Agent) agent = new http.Agent(agentOptions); // server only
109
return function request(_ref, cb) {
1110
var method = _ref.method;
1211
var url = _ref.url;

src/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Connection(config) {
1919
if (!this.config.headers['x-arango-version']) {
2020
this.config.headers['x-arango-version'] = this.config.arangoVersion;
2121
}
22-
this._request = createRequest(this.config.agentOptions);
22+
this._request = createRequest(this.config.agent, this.config.agentOptions);
2323
}
2424

2525
Connection.defaults = {

src/util/request.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ var parseUrl = require('url').parse;
44
var extend = require('extend');
55
var once = require('./once');
66

7-
module.exports = function (agentOptions) {
8-
var agent;
9-
if (http.Agent) agent = new http.Agent(agentOptions); // server only
7+
module.exports = function (agent, agentOptions) {
8+
if (!agent && http.Agent) agent = new http.Agent(agentOptions); // server only
109
return function request({method, url, headers, body}, cb) {
1110
var options = extend(parseUrl(url), {method, headers, agent});
1211
var callback = once(cb);

0 commit comments

Comments
 (0)