Compare commits

...
Author SHA1 Message Date
Ferenc HammerlandGitHub 7b24f92e45 Update proxy.test.ts 2023-03-02 14:51:56 +01:00
Ferenc Hammerl 4fefed4466 Fix linting 2023-03-02 13:48:37 +00:00
Ferenc Hammerl b511bc151f Better ipv6 definitions 2023-03-02 11:36:03 +00:00
Ferenc HammerlandGitHub 5d8e1ee68b Update proxy.ts 2023-03-02 11:38:57 +01:00
2 changed files with 13 additions and 10 deletions
+8 -6
View File
@@ -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((request, response) => {
response.writeHead(200)
request.pipe(response)
})
@@ -247,12 +247,14 @@ describe('proxy', () => {
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'http://localhost:8091'
)
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()
// proxy at _proxyUrl was ignored
expect(_proxyConnects).toEqual([])
} finally {
+5 -4
View File
@@ -73,10 +73,11 @@ export function checkBypass(reqUrl: URL): boolean {
}
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
const hostLower = host.toLowerCase()
return (
hostUpper === 'LOCALHOST' ||
hostUpper.startsWith('127.') ||
hostUpper.startsWith('::1')
hostLower === 'localhost' ||
hostLower.startsWith('127.') ||
hostLower.startsWith('[::1]') ||
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
)
}