From 200cfce4799c7e486802cdfc870058908f8e62d1 Mon Sep 17 00:00:00 2001 From: TekmonksGitHub Date: Mon, 3 Jun 2024 14:50:39 +0900 Subject: [PATCH] Fix in httpClient for ssl options and allow queueexecutor independent execution --- backend/server/lib/httpClient.js | 6 ++++-- backend/server/lib/queueExecutor.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/server/lib/httpClient.js b/backend/server/lib/httpClient.js index 75b02b8..2454448 100644 --- a/backend/server/lib/httpClient.js +++ b/backend/server/lib/httpClient.js @@ -156,7 +156,7 @@ function _doCall(reqStr, options, secure, sslObj) { const caller = secure && (!sslObj?._org_monkshu_httpclient_forceHTTP1) ? http2.connect(`https://${options.host}:${options.port||443}`) : secure ? https : http; // use the right connection factory based on http2, http1/ssl or http1/http let resp, ignoreEvents = false, resPiped, _skipProtocolErrors = false; - if (sslObj & typeof sslObj == "object") try { await _addSecureOptions(options, sslObj) } catch (err) { reject(err); return; }; + if (sslObj && typeof sslObj == "object") try { await _addSecureOptions(options, sslObj) } catch (err) { reject(err); return; }; const sendError = (error) => { reject(error); ignoreEvents = true; }; @@ -210,7 +210,7 @@ function _doCall(reqStr, options, secure, sslObj) { } else { LOG.info(`httpClient connecting to URL ${options.host}:${options.port}/${options.path} via HTTP1.`); - if (sslObj & typeof sslObj == "object") try{await _addSecureOptions(options, sslObj)} catch (err) {reject(err); return;}; + if (sslObj && typeof sslObj == "object") try{await _addSecureOptions(options, sslObj)} catch (err) {reject(err); return;}; const req = caller.request(options, res => { if (!_checkRequestResponseContentTypesMatch(options.headers, res.headers)) { sendError(`Content type doesn't match acceptable content. Requested ${options.headers.accept} != ${res.headers["content-type"]}.`); @@ -263,6 +263,8 @@ async function _addSecureOptions(options, sslObj) { options.cert = await _cacheReadFile(ssl.certPath); options.key = crypt.decrypt(await _cacheReadFile(ssl.encryptedKeyPath), sslObj.encryptionKey); } + + if (sslObj.rejectUnauthorized !== undefined) options.rejectUnauthorized = sslObj.rejectUnauthorized; } module.exports = { get, post, put, delete: deleteHttp, getHttps, postHttps, putHttps, deleteHttps, fetch, main }; diff --git a/backend/server/lib/queueExecutor.js b/backend/server/lib/queueExecutor.js index 4d99890..2bdcaca 100644 --- a/backend/server/lib/queueExecutor.js +++ b/backend/server/lib/queueExecutor.js @@ -11,7 +11,7 @@ const queue = []; const DEFAULT_QUEUE_CHECK_INTERVAL = 500; -const conf = require(`${CONSTANTS.CONFDIR}/queueexecutor.json`); +let conf; try {conf = require(`${CONSTANTS.CONFDIR}/queueexecutor.json`)} catch (err) {conf = {enabled: true}}; let queueInitialized = false; // to support server independent apps