Skip to content

Commit

Permalink
fix: HTTPS over HTTP proxy fails on mcafee proxy
Browse files Browse the repository at this point in the history
axios/axios#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.
  • Loading branch information
lili2311 committed Jan 31, 2022
1 parent 869e6bd commit 82a3883
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
package-lock.json
yarn.lock
.eslintcache
*.dccache
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions src/lib/request/request.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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}
Expand All @@ -83,5 +87,5 @@ const getConfig = () => {
export {
makeSnykRequest,
getConfig,
snykRequest
SnykRequest as snykRequest
}

0 comments on commit 82a3883

Please sign in to comment.