Skip to content

Commit 8105ec6

Browse files
ShubhamPalriwalabinarymist
authored andcommitted
Swap axios and proxy
Replace axios with got. Replace http-proxy-agent with hpagent. https://github.com/sindresorhus/got/blob/main/documentation/tips.md#proxying
1 parent 473c7a4 commit 8105ec6

File tree

3 files changed

+28
-111
lines changed

3 files changed

+28
-111
lines changed

package-lock.json

Lines changed: 7 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@
6969
"@aws-sdk/client-lambda": "^3.49.0",
7070
"@aws-sdk/client-servicediscovery": "^3.49.0",
7171
"@cucumber/cucumber": "^8.2.1",
72-
"@hapi/bourne": "^2.0.0",
72+
"@hapi/bourne": "^2.1.0",
7373
"@hapi/hapi": "^20.2.1",
74-
"axios": "^0.26.0",
7574
"convict": "^6.2.1",
7675
"convict-format-with-moment": "^6.2.0",
7776
"convict-format-with-validator": "^6.2.0",
7877
"got": "^12.0.1",
7978
"hpagent": "^0.1.2",
80-
"http-proxy-agent": "^5.0.0",
8179
"joi": "^17.6.0",
8280
"purpleteam-logger": "^2.0.0",
8381
"redis": "^4.0.2",

src/api/app/models/app.emissary.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// Doc: https://docs.aws.amazon.com/code-samples/latest/catalog/javascriptv3-lambda-src-MyLambdaApp-index.ts.html
1515
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';
1616
import { ServiceDiscoveryClient, ListInstancesCommand } from '@aws-sdk/client-servicediscovery';
17-
import axios from 'axios';
18-
import HttpProxyAgent from 'http-proxy-agent';
17+
import got from 'got';
18+
import { HttpProxyAgent } from 'hpagent';
1919
import Bourne from '@hapi/bourne';
2020

2121
// For complete sessionsProps
@@ -247,10 +247,22 @@ internals.s2ContainersReady = async ({ collectionOfS2ContainerHostNamesWithPorts
247247
// https://github.com/zaproxy/zaproxy/issues/3796#issuecomment-319376915
248248
// https://github.com/zaproxy/zaproxy/issues/3594
249249
{
250-
cloud() { return axios.get(`${protocol}://zap:${port}/UI`, { httpAgent: new HttpProxyAgent(`${protocol}://${mCV.appEmissaryHostName}:${mCV.appEmissaryPort}`) }); },
251-
local() { return axios.get(`${protocol}://${mCV.appEmissaryHostName}:${mCV.appEmissaryPort}/UI`); }
250+
cloud() {
251+
const agent = {
252+
http: new HttpProxyAgent({
253+
keepAlive: true,
254+
keepAliveMsecs: 1000,
255+
maxSockets: 256,
256+
maxFreeSockets: 256,
257+
scheduling: 'lifo',
258+
proxy: `${protocol}://${mCV.appEmissaryHostName}:${mCV.appEmissaryPort}`
259+
})
260+
};
261+
return got.get(`${protocol}://zap:${port}/UI`, { agent });
262+
},
263+
local() { return got.get(`${protocol}://${mCV.appEmissaryHostName}:${mCV.appEmissaryPort}/UI`); }
252264
}[process.env.NODE_ENV](),
253-
axios.get(`http://${mCV.seleniumHostName}:${mCV.seleniumPort}/wd/hub/status`)
265+
got.get(`http://${mCV.seleniumHostName}:${mCV.seleniumPort}/wd/hub/status`)
254266
]);
255267

256268
const results = await Promise.all(containerReadyPromises)
@@ -262,7 +274,7 @@ internals.s2ContainersReady = async ({ collectionOfS2ContainerHostNamesWithPorts
262274
log.warning(`${error.response.status}`, { tags: ['app.emissary'] });
263275
log.warning(`${error.response.headers}`, { tags: ['app.emissary'] });
264276
} else if (error.request && error.message) {
265-
log.warning(`The request was made to check emissary health but no response was received.\nThe error.message was: ${error.message}\nThe error.stack was: ${error.stack}`, { tags: ['app.emissary'] });
277+
log.warning(`The request was made to check emissary health but no response was received.\nThe error.message was: ${error.message}`, { tags: ['app.emissary'] });
266278
} else {
267279
log.warning('Something happened in setting up the request that triggered an Error', { tags: ['app.emissary'] });
268280
log.warning(`${error.message}`, { tags: ['app.emissary'] });
@@ -271,8 +283,8 @@ internals.s2ContainersReady = async ({ collectionOfS2ContainerHostNamesWithPorts
271283

272284
if (results) {
273285
const isReady = {
274-
appEmissary: (response) => (typeof response.data === 'string') && response.data.includes('ZAP API UI'),
275-
seleniumContainer: (response) => response.data.value.ready === true
286+
appEmissary: (response) => (typeof response.body === 'string') && response.body.includes('ZAP API UI'),
287+
seleniumContainer: (response) => Bourne.parse(response.body).value.ready === true
276288
};
277289
const containersThatAreNotReady = results.filter((e) => !(isReady.appEmissary(e) || isReady.seleniumContainer(e)));
278290
log.notice(`containersThatAreNotReady is: ${JSON.stringify(containersThatAreNotReady)}`, { tags: ['app.emissary', 's2ContainersReady'] });

0 commit comments

Comments
 (0)