diff --git a/carelink.js b/carelink.js index 15d509d..f448899 100644 --- a/carelink.js +++ b/carelink.js @@ -110,6 +110,11 @@ var Client = exports.Client = function (options) { return new URL(url).host; } + function getPath(url) { + let u = new URL(url); + return `${u.pathname}${u.search}`; + } + function doLogin(next) { let url = CARELINK_SECURITY_URL; logger.log('POST ' + url); @@ -118,9 +123,10 @@ var Client = exports.Client = function (options) { url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, form: { j_username: options.username, j_password: options.password, @@ -138,9 +144,10 @@ var Client = exports.Client = function (options) { url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, }), checkResponseThen(next) ); @@ -165,12 +172,12 @@ var Client = exports.Client = function (options) { logger.log('GET ' + url); request.get( - url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, }), checkResponseThen(next) ); @@ -185,9 +192,10 @@ var Client = exports.Client = function (options) { url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, }), checkResponseThen(next) ); @@ -205,9 +213,10 @@ var Client = exports.Client = function (options) { reqOptions({ jar: jar, gzip: true, - headers: { - host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, form: { sessionID: uriParam.get('sessionID'), sessionData: uriParam.get('sessionData'), @@ -237,9 +246,10 @@ var Client = exports.Client = function (options) { url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, form: { action: "consent", sessionID: ps.sessionID, @@ -261,9 +271,10 @@ var Client = exports.Client = function (options) { url, reqOptions({ jar: jar, - headers: { - Host: getHost(url), - }, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, }), checkResponseThen(next) ); @@ -279,8 +290,11 @@ var Client = exports.Client = function (options) { jar: jar, gzip: true, json: true, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, headers: { - Host: getHost(url), Authorization: "Bearer " + _.get(getCookie(CARELINKEU_TOKEN_COOKIE), 'value', ''), }, }), @@ -305,8 +319,11 @@ var Client = exports.Client = function (options) { var reqO = { jar: jar, gzip: true, + uri: url, + host: getHost(url), + path: getPath(url), + port: 443, headers: { - Host: getHost(url), }, }; if (CARELINK_EU) {