forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add http.proxyStrictSSL option fixes microsoft#155
- Loading branch information
1 parent
9b6bff1
commit eaa5bcf
Showing
6 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Url, parse as parseUrl } from 'url'; | ||
import HttpProxyAgent = require('http-proxy-agent'); | ||
import HttpsProxyAgent = require('https-proxy-agent'); | ||
|
||
function getAgent(rawRequestURL: string, proxyURL: string, strictSSL: boolean = true): any { | ||
let requestURL = parseUrl(rawRequestURL); | ||
let proxyEndpoint = parseUrl(proxyURL); | ||
|
||
if (!/^https?:$/.test(proxyEndpoint.protocol)) { | ||
return null; | ||
} | ||
|
||
if (requestURL.protocol === 'http:') { | ||
return new HttpProxyAgent(proxyURL); | ||
} | ||
|
||
return new HttpsProxyAgent({ | ||
host: proxyEndpoint.host, | ||
port: Number(proxyEndpoint.port), | ||
rejectUnauthorized: strictSSL | ||
}); | ||
} | ||
|
||
function getSystemProxyURI(requestURL: Url): string { | ||
if (requestURL.protocol === 'http:') { | ||
return process.env.HTTP_PROXY || process.env.http_proxy || null; | ||
} else if (requestURL.protocol === 'https:') { | ||
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getSystemProxyAgent(rawRequestURL: string): any { | ||
let requestURL = parseUrl(rawRequestURL); | ||
let proxyURL = getSystemProxyURI(requestURL); | ||
|
||
if (!proxyURL) { | ||
return null; | ||
} | ||
|
||
return getAgent(rawRequestURL, proxyURL); | ||
} | ||
|
||
export interface IOptions { | ||
proxyUrl?: string; | ||
strictSSL?: boolean; | ||
} | ||
|
||
export function getProxyAgent(rawRequestURL: string, options: IOptions = {}): any { | ||
console.log(rawRequestURL, options); | ||
|
||
if (!options.proxyUrl) { | ||
return getSystemProxyAgent(rawRequestURL); | ||
} | ||
|
||
return getAgent(rawRequestURL, options.proxyUrl, options.strictSSL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters