Skip to content

Commit 5b9cfc6

Browse files
author
Luca Forstner
committed
Fix behaviour of no_proxy env var
1 parent b1d6a60 commit 5b9cfc6

File tree

1 file changed

+10
-4
lines changed
  • packages/node/src/transports

1 file changed

+10
-4
lines changed

packages/node/src/transports/new.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface HttpTransportOptions extends BaseTransportOptions {
3636
*/
3737
export function makeNewHttpTransport(options: HttpTransportOptions): NewTransport {
3838
// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
39-
const proxy = filterNoProxy(options.url, options.proxy || process.env.http_proxy);
39+
const proxy = applyNoProxyOption(options.url, options.proxy || process.env.http_proxy);
4040

4141
const httpModule = options.httpModule ?? http;
4242

@@ -53,7 +53,7 @@ export function makeNewHttpTransport(options: HttpTransportOptions): NewTranspor
5353
*/
5454
export function makeNewHttpsTransport(options: HttpTransportOptions): NewTransport {
5555
// Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy`
56-
const proxy = filterNoProxy(options.url, options.proxy || process.env.https_proxy || process.env.http_proxy);
56+
const proxy = applyNoProxyOption(options.url, options.proxy || process.env.https_proxy || process.env.http_proxy);
5757

5858
const httpsModule = options.httpModule ?? https;
5959

@@ -72,10 +72,16 @@ export function makeNewHttpsTransport(options: HttpTransportOptions): NewTranspo
7272
* @param proxy The client configured proxy.
7373
* @returns A proxy the transport should use.
7474
*/
75-
function filterNoProxy(transportUrl: string, proxy: string | undefined): string | undefined {
75+
function applyNoProxyOption(transportUrl: string, proxy: string | undefined): string | undefined {
7676
const { no_proxy } = process.env;
7777

78-
const urlIsExemptFromProxy = no_proxy && no_proxy.split(',').some(exemption => transportUrl.endsWith(exemption));
78+
const { host: transportUrlHost, hostname: transportUrlHostname } = new URL(transportUrl);
79+
80+
const urlIsExemptFromProxy =
81+
no_proxy &&
82+
no_proxy
83+
.split(',')
84+
.some(exemption => transportUrlHost.endsWith(exemption) || transportUrlHostname.endsWith(exemption));
7985

8086
if (urlIsExemptFromProxy) {
8187
return undefined;

0 commit comments

Comments
 (0)