Skip to content

Commit ed01d94

Browse files
authored
fix(node): Prioritize globalAgent while figuring out protocol.
1 parent 6608d39 commit ed01d94

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

packages/node/src/integrations/utils/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ export function normalizeRequestArgs(
152152
// Worst case we end up populating protocol with undefined, which it already is
153153
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any */
154154
requestOptions.protocol =
155+
(httpModule?.globalAgent as any)?.protocol ||
155156
(requestOptions.agent as any)?.protocol ||
156-
(requestOptions._defaultAgent as any)?.protocol ||
157-
(httpModule?.globalAgent as any)?.protocol;
157+
(requestOptions._defaultAgent as any)?.protocol
158158
/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any */
159159
}
160160

packages/node/test/integrations/http.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { parseSemver } from '@sentry/utils';
66
import * as http from 'http';
77
import * as https from 'https';
88
import * as nock from 'nock';
9+
import * as HttpsProxyAgent from "https-proxy-agent";
910

1011
import { Breadcrumb } from '../../src';
1112
import { NodeClient } from '../../src/client';
@@ -175,4 +176,31 @@ describe('default protocols', () => {
175176
const b = await p;
176177
expect(b.data?.url).toEqual(expect.stringContaining('https://'));
177178
});
179+
180+
it('makes https request over http proxy', async () => {
181+
const key = 'catcatchers';
182+
const p = captureBreadcrumb(key);
183+
let nockProtocol = 'https:';
184+
185+
const proxy = "http://<PROXY_URL>:3128";
186+
const agent = new HttpsProxyAgent(proxy);
187+
188+
if (NODE_VERSION.major && NODE_VERSION.major < 9) {
189+
nockProtocol = 'http:';
190+
}
191+
192+
nock(`${nockProtocol}://${key}.ingest.sentry.io`)
193+
.get('/api/123122332/store/')
194+
.reply(200);
195+
196+
https.get({
197+
host: `${key}.ingest.sentry.io`,
198+
path: '/api/123122332/store/',
199+
timeout: 300,
200+
agent
201+
});
202+
203+
const b = await p;
204+
expect(b.data?.url).toEqual(expect.stringContaining('https://'));
205+
})
178206
});

0 commit comments

Comments
 (0)