1
0
Fork 0

Revert "Bypass proxy on loopback IPs"

This reverts commit 8d92c9c903.
pull/1346/merge
Ferenc Hammerl 2023-03-01 13:48:44 +00:00
parent 8d92c9c903
commit 1f4b3fac06
2 changed files with 8 additions and 28 deletions

View File

@ -223,28 +223,18 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:443']) expect(_proxyConnects).toEqual(['httpbin.org:443'])
}) })
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => { it('HttpClient does basic https get request when bypass proxy', async () => {
// setup a server listening on localhost:8091 process.env['https_proxy'] = _proxyUrl
var server = http.createServer(function (request, response) { process.env['no_proxy'] = 'httpbin.org'
response.writeHead(200);
request.pipe(response);
});
await server.listen(8091)
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient() const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get( const res: httpm.HttpClientResponse = await httpClient.get(
'http://localhost:8091' 'https://httpbin.org/get'
) )
expect(res.message.statusCode).toBe(200) expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody() const body: string = await res.readBody()
expect(body).toEqual(''); const obj = JSON.parse(body)
// proxy at _proxyUrl was ignored expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toEqual(undefined) expect(_proxyConnects).toHaveLength(0)
}
finally {
await server.close()
}
}) })
it('proxyAuth not set in tunnel agent when authentication is not provided', async () => { it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {

View File

@ -25,11 +25,6 @@ export function checkBypass(reqUrl: URL): boolean {
return false return false
} }
const reqHost = reqUrl.hostname
if (isLoopbackAddress(reqHost)) {
return true
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '' const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
if (!noProxy) { if (!noProxy) {
return false return false
@ -71,8 +66,3 @@ export function checkBypass(reqUrl: URL): boolean {
return false return false
} }
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
return hostUpper === 'LOCALHOST' || hostUpper.startsWith('127.') || hostUpper.startsWith('::1')
}