From 82a3883ffd29814498ac3293089fb051deaf7c22 Mon Sep 17 00:00:00 2001 From: ghe Date: Mon, 31 Jan 2022 11:34:48 +0000 Subject: [PATCH] fix: HTTPS over HTTP proxy fails on mcafee proxy https://github.com/axios/axios/issues/3384 HTTPS over HTTP Proxy Fails with 500 handshakefailed on mcafee proxy. mcafee initialize server context:handshakefailed:server state 1:state 9:Application response 500 handshakefailed With HTTP_PROXY and HTTPS_PROXY set, curl works but axios.get fails. --- .gitignore | 1 + package.json | 1 + src/lib/request/request.ts | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3a10c1d..9a2ca74 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist package-lock.json yarn.lock .eslintcache +*.dccache diff --git a/package.json b/package.json index d29673b..17db606 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "axios": "0.21.4", "chalk": "^4.0.0", "debug": "^4.1.1", + "global-agent": "3.0.0", "leaky-bucket-queue": "0.0.2", "lodash": "4.17.21", "snyk-config": "^4.0.0", diff --git a/src/lib/request/request.ts b/src/lib/request/request.ts index 4de479f..75b3f49 100644 --- a/src/lib/request/request.ts +++ b/src/lib/request/request.ts @@ -1,8 +1,12 @@ const Configstore = require('@snyk/configstore'); -import axios from 'axios' +import axios from 'axios'; import * as Error from '../customErrors/apiError' -interface snykRequest { +// Fixes issue https://github.com/axios/axios/issues/3384 +// where HTTPS over HTTP Proxy Fails with 500 handshakefailed on mcafee proxy +import 'global-agent/bootstrap'; + +interface SnykRequest { verb: string, url: string, body?: string, @@ -21,11 +25,11 @@ const getTopParentModuleName = (parent: NodeModule | null): string => { } } -const makeSnykRequest = async (request: snykRequest, snykToken: string = '', userAgentPrefix:string = '') => { +const makeSnykRequest = async (request: SnykRequest, snykToken: string = '', userAgentPrefix:string = '') => { const userConfig = getConfig() const token = snykToken == '' ? userConfig.token : snykToken - let topParentModuleName = getTopParentModuleName(module.parent as any) + const topParentModuleName = getTopParentModuleName(module.parent as any) const userAgentPrefixChecked = userAgentPrefix != '' && !userAgentPrefix.endsWith('/') ? userAgentPrefix+'/': userAgentPrefix const requestHeaders: Object = { 'Content-Type': 'application/json', @@ -74,7 +78,7 @@ const makeSnykRequest = async (request: snykRequest, snykToken: string = '', use } -const getConfig = () => { +const getConfig = (): {endpoint: string, token: string} => { const snykApiEndpoint: string = process.env.SNYK_API || new Configstore('snyk').get('endpoint') || 'https://snyk.io/api/v1' const snykToken = process.env.SNYK_TOKEN || new Configstore('snyk').get('api') return {endpoint: snykApiEndpoint, token: snykToken} @@ -83,5 +87,5 @@ const getConfig = () => { export { makeSnykRequest, getConfig, - snykRequest + SnykRequest as snykRequest }