Skip to content

Commit 3d25b0e

Browse files
elliotttfwooldridge
authored andcommitted
Allow custom http(s) agent to be used
Currently a default http(s) agent is provided via Yakaa if the `agent` configuration option is not set. If it is set though the agent is completely omitted from the `connectionParams` object. This change will maintain existing behavior of providing a default agent but also allows users to specify one of their own.
1 parent 51f74a9 commit 3d25b0e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/marklogic.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,17 @@ function initClient(client, inputParams) {
621621
});
622622
connectionParams.agent = new YAgent.SSL(agentOptions);
623623
}
624+
else {
625+
connectionParams.agent = inputParams.agent;
626+
}
624627
} else {
625628
client.request = http.request;
626629
if (noAgent) {
627630
connectionParams.agent = new YAgent(agentOptions);
628631
}
632+
else {
633+
connectionParams.agent = inputParams.agent;
634+
}
629635
}
630636
}
631637
function releaseClient(client) {

test-basic/client.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var testconfig = require('../etc/test-config.js');
2121
var marklogic = require('../');
2222
var q = marklogic.queryBuilder;
2323

24+
var YAgent = require('yakaa');
25+
2426
// TODO: setup should create user with eval-in role
2527
var connection = {
2628
user: 'admin',
@@ -43,7 +45,17 @@ Object.keys(connection).forEach(function(key){
4345
}
4446
});
4547
var otherDb = marklogic.createDatabaseClient(otherConnection);
46-
48+
49+
var agentConnection = {
50+
agent: new YAgent({keepAlive: true, keepAliveTimeoutMsecs: 1000})
51+
}
52+
Object.keys(otherConnection).forEach(function(key){
53+
if (agentConnection[key] === undefined) {
54+
agentConnection[key] = otherConnection[key];
55+
}
56+
});
57+
var agentDb = marklogic.createDatabaseClient(agentConnection);
58+
4759
describe('database clients', function() {
4860
it('should write in a default db and read in a specified db', function(done) {
4961
db.documents.write({
@@ -81,4 +93,12 @@ describe('database clients', function() {
8193
})
8294
.catch(done);
8395
});
96+
it('should use a default agent', function(done) {
97+
otherDb.connectionParams.agent.options.keepAlive.should.equal(true);
98+
done();
99+
});
100+
it('should use a custom agent', function(done) {
101+
agentDb.connectionParams.agent.options.keepAliveTimeoutMsecs.should.equal(1000);
102+
done();
103+
});
84104
});

0 commit comments

Comments
 (0)