Skip to content

Commit f92189d

Browse files
nezedSlava Baginov
authored andcommitted
Improve http options providing
1 parent 263e564 commit f92189d

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/clickhouse.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var JSONStream = require ('./streams').JSONStream;
1313

1414
var parseError = require ('./parse-error');
1515

16-
var NATIVE_HTTP_OPTIONS = require ('./consts').NATIVE_HTTP_OPTIONS
16+
var LIBRARY_SPECIFIC_OPTIONS = require ('./consts').LIBRARY_SPECIFIC_OPTIONS;
1717

1818
function httpResponseHandler (stream, reqParams, reqData, cb, response) {
1919
var str;
@@ -216,13 +216,18 @@ function ClickHouse (options) {
216216
}
217217

218218
ClickHouse.prototype.getReqParams = function () {
219+
// avoid to set defaults - node http module is not happy
220+
var reqParamNames = Object.keys(this.options)
221+
.filter(function(name) {
222+
return !LIBRARY_SPECIFIC_OPTIONS.has(name);
223+
});
224+
219225
var urlObject = {};
220226

221-
// avoid to set defaults - node http module is not happy
222-
NATIVE_HTTP_OPTIONS.forEach (function (k) {
223-
if (this.options.hasOwnProperty(k))
224-
urlObject[k] = this.options[k];
225-
}, this);
227+
for (var name of reqParamNames) {
228+
urlObject[name] = this.options[name];
229+
}
230+
226231
if (this.options.hasOwnProperty('user') || this.options.hasOwnProperty('password')) {
227232
urlObject.auth = encodeURIComponent(this.options.user || 'default')
228233
+ ':'

src/consts.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
exports.NATIVE_HTTP_OPTIONS = [
2-
'protocol',
3-
'auth',
4-
'host',
5-
'hostname',
6-
'port',
7-
'path',
8-
'localAddress',
9-
'headers',
10-
'agent',
11-
'createConnection',
12-
'timeout',
13-
]
1+
exports.LIBRARY_SPECIFIC_OPTIONS = new Set([
2+
'omitFormat',
3+
'dataObjects',
4+
'format',
5+
'queryOptions',
6+
'useQueryString',
7+
'user',
8+
'password'
9+
]);

0 commit comments

Comments
 (0)