From cadcebdfa4a811248343db770ea56eee3d84397b Mon Sep 17 00:00:00 2001 From: "nezed [CustoMac]" Date: Sun, 26 May 2019 16:59:33 +0300 Subject: [PATCH] Improve http options providing --- src/clickhouse.js | 12 +++++++----- src/consts.js | 29 ++++++++++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/clickhouse.js b/src/clickhouse.js index 8876aa3..1f11774 100644 --- a/src/clickhouse.js +++ b/src/clickhouse.js @@ -13,7 +13,7 @@ var JSONStream = require ('./streams').JSONStream; var parseError = require ('./parse-error'); -var NATIVE_HTTP_OPTIONS = require ('./consts').NATIVE_HTTP_OPTIONS +var LIBRARY_SPECIFIC_OPTIONS = require ('./consts').LIBRARY_SPECIFIC_OPTIONS; function httpResponseHandler (stream, reqParams, reqData, cb, response) { var str; @@ -219,10 +219,12 @@ ClickHouse.prototype.getReqParams = function () { var urlObject = {}; // avoid to set defaults - node http module is not happy - NATIVE_HTTP_OPTIONS.forEach (function (k) { - if (this.options.hasOwnProperty(k)) - urlObject[k] = this.options[k]; - }, this); + for (var name of Object.keys(this.options)) { + if (!LIBRARY_SPECIFIC_OPTIONS.has(name)) { + urlObject[name] = this.options[name]; + } + } + if (this.options.hasOwnProperty('user') || this.options.hasOwnProperty('password')) { urlObject.auth = encodeURIComponent(this.options.user || 'default') + ':' diff --git a/src/consts.js b/src/consts.js index 20c6fdb..32a2a6f 100644 --- a/src/consts.js +++ b/src/consts.js @@ -1,13 +1,16 @@ -exports.NATIVE_HTTP_OPTIONS = [ - 'protocol', - 'auth', - 'host', - 'hostname', - 'port', - 'path', - 'localAddress', - 'headers', - 'agent', - 'createConnection', - 'timeout', -] +exports.LIBRARY_SPECIFIC_OPTIONS = new Set([ + // "Auth" shorthand + 'user', + 'password', + + // Database settings go to query string + 'queryOptions', + + // Driver options + 'dataObjects', + 'format', + 'syncParser', + 'omitFormat', + 'readonly', + 'useQueryString' +]);