Skip to content

Commit 91d3933

Browse files
authored
Prepend http:// to http(s)_proxy env if missing (#1439)
* Prepend http:// to http(s)_proxy env if missing * Formatting * Fix linting
1 parent a6bf872 commit 91d3933

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/http-client/__tests__/proxy.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ describe('proxy', () => {
9191
expect(proxyUrl).toBeDefined()
9292
})
9393

94+
it('getProxyUrl returns proxyUrl if http_proxy has no protocol', () => {
95+
process.env['http_proxy'] = 'myproxysvr'
96+
const proxyUrl = pm.getProxyUrl(new URL('http://github.com'))
97+
expect(proxyUrl?.toString()).toBe('http://myproxysvr/')
98+
})
99+
94100
it('checkBypass returns true if host as no_proxy list', () => {
95101
process.env['no_proxy'] = 'myserver'
96102
const bypass = pm.checkBypass(new URL('https://myserver'))

packages/http-client/src/proxy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ export function getProxyUrl(reqUrl: URL): URL | undefined {
1414
})()
1515

1616
if (proxyVar) {
17-
return new URL(proxyVar)
17+
try {
18+
return new URL(proxyVar)
19+
} catch {
20+
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
21+
return new URL(`http://${proxyVar}`)
22+
}
1823
} else {
1924
return undefined
2025
}

0 commit comments

Comments
 (0)