diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 60d26d280..bb461edb3 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -47,26 +47,29 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll const options = getOptions(); const insecure = get(options, 'insecure', false); + const httpsAgentRequestFields = {}; if(insecure) { - request.httpsAgent = new https.Agent({ - rejectUnauthorized: false - }); + httpsAgentRequestFields['rejectUnauthorized'] = false; } else { const cacertArray = [options['cacert'], process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS]; - const cacertFile = cacertArray.find(el => el); + const cacert = cacertArray.find(el => el); if (cacert && cacert.length > 1) { try { - caCrt = fs.readFileSync(cacert) - request.httpsAgent = new https.Agent({ - ca: caCrt - }); + caCrt = fs.readFileSync(cacert); + httpsAgentRequestFields['ca'] = caCrt; } catch(err) { console.log('Error reading CA cert file:' + cacert, err); } } } + if (Object.keys(httpsAgentRequestFields).length > 0) { + request.httpsAgent = new https.Agent({ + ...httpsAgentRequestFields + }); + } + // stringify the request url encoded params if(request.headers['content-type'] === 'application/x-www-form-urlencoded') { request.data = qs.stringify(request.data); diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 29860758b..a8cba7400 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -148,11 +148,9 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { const preferences = getPreferences(); const sslVerification = get(preferences, 'request.sslVerification', true); - + const httpsAgentRequestFields = {}; if(!sslVerification) { - request.httpsAgent = new https.Agent({ - rejectUnauthorized: false - }); + httpsAgentRequestFields['rejectUnauthorized'] = false; } else { const cacertArray = [preferences['cacert'], process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS]; @@ -160,16 +158,20 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => { if (cacertFile && cacertFile.length > 1) { try { const fs = require('fs'); - caCrt = fs.readFileSync(cacertFile) - request.httpsAgent = new https.Agent({ - ca: caCrt - }); + caCrt = fs.readFileSync(cacertFile); + httpsAgentRequestFields['ca'] = caCrt; } catch(err) { console.log('Error reading CA cert file:' + cacertFile, err); } } } + if (Object.keys(httpsAgentRequestFields).length > 0) { + request.httpsAgent = new https.Agent({ + ...httpsAgentRequestFields + }); + } + const response = await axios(request); // run post-response vars