1
0
Fork 0

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

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

* Formatting

* Fix linting
pull/1443/merge @actions/artifact@1.1.1
Ferenc Hammerl 2023-06-22 11:03:38 +02:00 committed by GitHub
parent a6bf8726aa
commit 91d3933eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -91,6 +91,12 @@ describe('proxy', () => {
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', () => {
process.env['no_proxy'] = 'myserver'
const bypass = pm.checkBypass(new URL('https://myserver'))

View File

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