diff --git a/__tests__/proxy.test.ts b/__tests__/proxy.test.ts index 97cf785..1a0e28a 100644 --- a/__tests__/proxy.test.ts +++ b/__tests__/proxy.test.ts @@ -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')) diff --git a/src/proxy.ts b/src/proxy.ts index 1a967e3..32afce6 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -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 }