From 93284f92d7596f82b361b6c5b93d4cb921739376 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Wed, 6 Feb 2019 21:20:34 +0100 Subject: [PATCH] Fix issue #87 (DNS lookup for localhost socks proxy) --- src/proxy.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/proxy.ts b/src/proxy.ts index b723c98..abffe33 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -6,6 +6,11 @@ import * as Logging from './logging'; import { FileSystemConfig } from './manager'; import { toPromise } from './toPromise'; +async function resolveHostname(hostname: string): Promise { + if (hostname === 'localhost') return ['127.0.0.1']; + return toPromise(cb => dns.resolve(hostname, cb)); +} + function validateConfig(config: FileSystemConfig) { if (!config.proxy) throw new Error(`Missing field 'config.proxy'`); if (!config.proxy.host) throw new Error(`Missing field 'config.proxy.host'`); @@ -20,7 +25,7 @@ export async function socks(config: FileSystemConfig): Promise(cb => dns.resolve(config.proxy!.host, cb)))[0]; + const ipaddress = (await resolveHostname(config.proxy!.host))[0]; if (!ipaddress) throw new Error(`Couldn't resolve '${config.proxy!.host}'`); Logging.debug(`\tConnecting to ${config.host}:${config.port} over ${config.proxy!.type} proxy at ${ipaddress}:${config.proxy!.port}`); const con = await SocksClient.createConnection({