Skip to content

Commit

Permalink
Prepend http:// to http(s)_proxy env if missing (#1439)
Browse files Browse the repository at this point in the history
* Prepend http:// to http(s)_proxy env if missing

* Formatting

* Fix linting
  • Loading branch information
fhammerl authored Jun 22, 2023
1 parent a6bf872 commit 91d3933
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/http-client/__tests__/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
7 changes: 6 additions & 1 deletion packages/http-client/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 91d3933

Please sign in to comment.