diff --git a/package-lock.json b/package-lock.json index 7699a223..bd7f4911 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16705,6 +16705,7 @@ "lodash": "^4.17.21", "mustache": "^4.2.0", "qs": "^6.11.0", + "socks-proxy-agent": "^8.0.2", "yargs": "^17.6.2" }, "bin": { @@ -20024,6 +20025,7 @@ "lodash": "^4.17.21", "mustache": "^4.2.0", "qs": "^6.11.0", + "socks-proxy-agent": "*", "yargs": "^17.6.2" }, "dependencies": { @@ -21161,7 +21163,7 @@ "nanoid": "3.3.4", "node-machine-id": "^1.1.12", "qs": "^6.11.0", - "socks-proxy-agent": "*", + "socks-proxy-agent": "^8.0.2", "uuid": "^9.0.0", "vm2": "^3.9.13", "yup": "^0.32.11" diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json index dca3a823..77d7bc59 100644 --- a/packages/bruno-cli/package.json +++ b/packages/bruno-cli/package.json @@ -39,6 +39,7 @@ "lodash": "^4.17.21", "mustache": "^4.2.0", "qs": "^6.11.0", + "socks-proxy-agent": "^8.0.2", "yargs": "^17.6.2" } } diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index f86e1b02..3e56bf0a 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -13,6 +13,7 @@ const { getOptions } = require('../utils/bru'); const https = require('https'); const { HttpsProxyAgent } = require('https-proxy-agent'); const { HttpProxyAgent } = require('http-proxy-agent'); +const { SocksProxyAgent } = require('socks-proxy-agent'); const { makeAxiosInstance } = require('../utils/axios-instance'); const runSingleRequest = async function ( @@ -96,7 +97,7 @@ const runSingleRequest = async function ( // set proxy if enabled const proxyEnabled = get(brunoConfig, 'proxy.enabled', false); if (proxyEnabled) { - let proxy; + let proxyUri; const interpolationOptions = { envVars: envVariables, collectionVariables, @@ -107,6 +108,7 @@ const runSingleRequest = async function ( const proxyHostname = interpolateString(get(brunoConfig, 'proxy.hostname'), interpolationOptions); const proxyPort = interpolateString(get(brunoConfig, 'proxy.port'), interpolationOptions); const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false); + const socksEnabled = proxyProtocol.includes('socks'); interpolateString; @@ -114,17 +116,25 @@ const runSingleRequest = async function ( const proxyAuthUsername = interpolateString(get(brunoConfig, 'proxy.auth.username'), interpolationOptions); const proxyAuthPassword = interpolateString(get(brunoConfig, 'proxy.auth.password'), interpolationOptions); - proxy = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`; + proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`; } else { - proxy = `${proxyProtocol}://${proxyHostname}:${proxyPort}`; + proxyUri = `${proxyProtocol}://${proxyHostname}:${proxyPort}`; } - request.httpsAgent = new HttpsProxyAgent( - proxy, - Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined - ); + if (socksEnabled) { + const socksProxyAgent = new SocksProxyAgent(proxyUri); - request.httpAgent = new HttpProxyAgent(proxy); + request.httpsAgent = socksProxyAgent; + + request.httpAgent = socksProxyAgent; + } else { + request.httpsAgent = new HttpsProxyAgent( + proxyUri, + Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined + ); + + request.httpAgent = new HttpProxyAgent(proxyUri); + } } else if (Object.keys(httpsAgentRequestFields).length > 0) { request.httpsAgent = new https.Agent({ ...httpsAgentRequestFields