Skip to content

Commit cadcebd

Browse files
committed
Improve http options providing
1 parent e004e6a commit cadcebd

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/clickhouse.js

Lines changed: 7 additions & 5 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;
@@ -219,10 +219,12 @@ ClickHouse.prototype.getReqParams = function () {
219219
var urlObject = {};
220220

221221
// 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);
222+
for (var name of Object.keys(this.options)) {
223+
if (!LIBRARY_SPECIFIC_OPTIONS.has(name)) {
224+
urlObject[name] = this.options[name];
225+
}
226+
}
227+
226228
if (this.options.hasOwnProperty('user') || this.options.hasOwnProperty('password')) {
227229
urlObject.auth = encodeURIComponent(this.options.user || 'default')
228230
+ ':'

src/consts.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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+
// "Auth" shorthand
3+
'user',
4+
'password',
5+
6+
// Database settings go to query string
7+
'queryOptions',
8+
9+
// Driver options
10+
'dataObjects',
11+
'format',
12+
'syncParser',
13+
'omitFormat',
14+
'readonly',
15+
'useQueryString'
16+
]);

0 commit comments

Comments
 (0)