Skip to content

Commit 31c87db

Browse files
ehennumShiva Verma
authored andcommitted
use native Node.js HTTP Agent #544
1 parent dbd3037 commit 31c87db

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

lib/marklogic.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'use strict';
1717
var http = require('http');
1818
var https = require('https');
19-
var YAgent = require('yakaa');
2019

2120
var mlutil = require('./mlutil.js');
2221
var mllog = require('./mllog.js');
@@ -765,22 +764,22 @@ function initClient(client, inputParams) {
765764
if (isSSL) {
766765
client.request = https.request;
767766
if (noAgent) {
768-
['ca', 'cert', 'ciphers', 'key', 'passphrase', 'pfx',
769-
'rejectUnauthorized', 'secureProtocol'].
770-
forEach(function certificateKeyCopier(key) {
771-
var value = inputParams[key];
772-
if (value != null) {
773-
agentOptions[key] = value;
774-
}
775-
});
776-
connectionParams.agent = new YAgent.SSL(agentOptions);
767+
mlutil.copyProperties(inputParams, agentOptions, [
768+
'ca', 'cert', 'ciphers', 'keepAliveMsecs', 'key', 'maxSockets',
769+
'maxFreeSockets', 'passphrase', 'pfx', 'rejectUnauthorized',
770+
'secureProtocol', 'timeout'
771+
]);
772+
connectionParams.agent = new https.Agent(agentOptions);
777773
} else {
778774
connectionParams.agent = inputParams.agent;
779775
}
780776
} else {
781777
client.request = http.request;
782778
if (noAgent) {
783-
connectionParams.agent = new YAgent(agentOptions);
779+
mlutil.copyProperties(inputParams, agentOptions, [
780+
'keepAliveMsecs', 'maxSockets', 'maxFreeSockets', 'timeout'
781+
]);
782+
connectionParams.agent = new http.Agent(agentOptions);
784783
} else {
785784
connectionParams.agent = inputParams.agent;
786785
}

lib/mlutil.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ function asArray() {
4343
return args;
4444
}
4545
}
46-
function copyProperties(source, target) {
47-
var dest = (arguments.length > 1) ? target : {};
46+
function copyProperties(source, target, srcKeys) {
47+
var dest = (arguments.length > 1) ? target : {};
48+
var isNamed = Array.isArray(srcKeys);
49+
var keys = isNamed ? srcKeys : Object.keys(source);
4850

4951
// for...in not currently optimized by v8
50-
var keys = Object.keys(source);
5152
var keyLen = keys.length;
5253
for (var i=0; i < keyLen; i++) {
5354
var key = keys[i];
54-
dest[key] = source[key];
55+
var val = source[key];
56+
if (!isNamed || (val !== void 0 && val !== null)) {
57+
dest[key] = val;
58+
}
5559
}
5660

5761
return dest;

npm-shrinkwrap.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"multipart-stream": "^2.0.1",
3636
"qs": "^6.9.1",
3737
"through2": "^3.0.1",
38-
"www-authenticate": "^0.6.2",
39-
"yakaa": "^1.0.1"
38+
"www-authenticate": "^0.6.2"
4039
},
4140
"repository": {
4241
"type": "git",

test-basic/client.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
var assert = require('assert');
1717
var should = require('should');
1818

19+
var http = require('http');
20+
1921
var testconfig = require('../etc/test-config.js');
2022

2123
var marklogic = require('../');
2224
var q = marklogic.queryBuilder;
2325

24-
var YAgent = require('yakaa');
25-
2626
// 'rest-evaluator' user can evaluate against an alternate db:
2727
// http://docs.marklogic.com/guide/rest-dev/intro#id_72318
2828
var connection = {
@@ -48,8 +48,13 @@ Object.keys(connection).forEach(function(key){
4848
var otherDb = marklogic.createDatabaseClient(otherConnection);
4949

5050
var agentConnection = {
51+
<<<<<<< HEAD
5152
agent: new YAgent({keepAlive: true, keepAliveTimeoutMsecs: 1000})
5253
}
54+
=======
55+
agent: new http.Agent({keepAlive: true, keepAliveTimeoutMsecs: 1000})
56+
};
57+
>>>>>>> 1ad64b6... use native Node.js HTTP Agent #544
5358
Object.keys(otherConnection).forEach(function(key){
5459
if (agentConnection[key] === undefined) {
5560
agentConnection[key] = otherConnection[key];

0 commit comments

Comments
 (0)