From b511bc151f9ff40c03292ba8354f7e045c682c11 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:36:03 +0000 Subject: [PATCH] Better ipv6 definitions --- packages/http-client/__tests__/proxy.test.ts | 22 +++++++++++++++----- packages/http-client/src/proxy.ts | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/http-client/__tests__/proxy.test.ts b/packages/http-client/__tests__/proxy.test.ts index 9ad9c6d1..38d8dd4d 100644 --- a/packages/http-client/__tests__/proxy.test.ts +++ b/packages/http-client/__tests__/proxy.test.ts @@ -28,7 +28,7 @@ describe('proxy', () => { _clearVars() }) - afterEach(() => {}) + afterEach(() => { }) afterAll(async () => { _clearVars() @@ -239,7 +239,7 @@ describe('proxy', () => { it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => { // setup a server listening on localhost:8091 - const server = http.createServer(function(request, response) { + const server = http.createServer(function (request, response) { response.writeHead(200) request.pipe(response) }) @@ -247,12 +247,24 @@ describe('proxy', () => { try { process.env['http_proxy'] = _proxyUrl const httpClient = new httpm.HttpClient() - const res: httpm.HttpClientResponse = await httpClient.get( + let res = await httpClient.get( 'http://localhost:8091' ) expect(res.message.statusCode).toBe(200) - const body: string = await res.readBody() - expect(body).toEqual('') + res = await httpClient.get( + 'http://127.0.0.1:8091' + ) + expect(res.message.statusCode).toBe(200) + + // no support for ipv6 for now + expect(httpClient.get( + 'http://[::1]:8091')).rejects.toThrow() + + // ipv6 not supported atm + // expect(async () => await httpClient.get( + // 'http://[::1]:8091' + // )).toThrow() + // proxy at _proxyUrl was ignored expect(_proxyConnects).toEqual([]) } finally { diff --git a/packages/http-client/src/proxy.ts b/packages/http-client/src/proxy.ts index fdcad2ad..8727dfd1 100644 --- a/packages/http-client/src/proxy.ts +++ b/packages/http-client/src/proxy.ts @@ -77,6 +77,7 @@ function isLoopbackAddress(host: string): boolean { return ( hostLower === 'localhost' || hostLower.startsWith('127.') || - hostLower.startsWith('::1') + hostLower.startsWith('[::1]') || + hostLower.startsWith('[0:0:0:0:0:0:0:1]') ) }