From 61d77ac765ad432ed1d655846218f8f0d875c759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Martin?= Date: Wed, 24 Apr 2019 19:00:16 +0200 Subject: [PATCH] fix: use proxy only for remote requests Do not use the proxy for requests to localhost or 127.0.0.1 when NativeScript is configured to use the proxy. Partially fixes issue #2313, since requests to localhost will be possible in corporate proxy environments. --- lib/common/http-client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/common/http-client.ts b/lib/common/http-client.ts index 6aaec22c5d..5c970b7eea 100644 --- a/lib/common/http-client.ts +++ b/lib/common/http-client.ts @@ -289,7 +289,9 @@ private defaultUserAgent: string; * @param {string} requestProto The protocol used for the current request - http or https. */ private async useProxySettings(proxySettings: IProxySettings, cliProxySettings: IProxySettings, options: any, headers: any, requestProto: string): Promise { - if (proxySettings || cliProxySettings) { + const isLocalRequest = options.host === "localhost" || options.host === "127.0.0.1"; + // don't use the proxy for requests to localhost + if (!isLocalRequest && (proxySettings || cliProxySettings)) { const proto = (proxySettings && proxySettings.protocol) || cliProxySettings.protocol || "http:"; const host = (proxySettings && proxySettings.hostname) || cliProxySettings.hostname; const port = (proxySettings && proxySettings.port) || cliProxySettings.port;