1
0
Fork 0

Prepend http:// to http(s)_proxy env if missing

pull/1439/head
Ferenc Hammerl 2023-06-20 12:16:21 +00:00
parent a6bf8726aa
commit 17e0aec811
2 changed files with 13 additions and 1 deletions

View File

@ -91,6 +91,12 @@ describe('proxy', () => {
expect(proxyUrl).toBeDefined() expect(proxyUrl).toBeDefined()
}) })
it('getProxyUrl returns proxyUrl if http_proxy has no protocol', () => {
process.env['http_proxy'] = 'myproxysvr'
const proxyUrl = pm.getProxyUrl(new URL('http://github.com'))
expect(proxyUrl?.toString()).toBe('http://myproxysvr/')
})
it('checkBypass returns true if host as no_proxy list', () => { it('checkBypass returns true if host as no_proxy list', () => {
process.env['no_proxy'] = 'myserver' process.env['no_proxy'] = 'myserver'
const bypass = pm.checkBypass(new URL('https://myserver')) const bypass = pm.checkBypass(new URL('https://myserver'))

View File

@ -14,7 +14,13 @@ export function getProxyUrl(reqUrl: URL): URL | undefined {
})() })()
if (proxyVar) { if (proxyVar) {
try {
return new URL(proxyVar) return new URL(proxyVar)
}
catch {
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
return new URL('http://' + proxyVar)
}
} else { } else {
return undefined return undefined
} }