From e58de1a6e48868356e4e706effd384cdf5073652 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Thu, 12 Jun 2025 10:50:06 +0200 Subject: [PATCH] fix(core): Fix http requests by using correct agent (#16258) --- .../request-helper-functions.test.ts | 23 +++++++++++++------ .../utils/request-helper-functions.ts | 3 +-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/core/src/execution-engine/node-execution-context/utils/__tests__/request-helper-functions.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/request-helper-functions.test.ts index 023f570229..84f393d240 100644 --- a/packages/core/src/execution-engine/node-execution-context/utils/__tests__/request-helper-functions.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/request-helper-functions.test.ts @@ -1,6 +1,7 @@ import FormData from 'form-data'; +import { Agent as HttpAgent } from 'http'; import { HttpProxyAgent } from 'http-proxy-agent'; -import { Agent } from 'https'; +import { Agent as HttpsAgent } from 'https'; import { HttpsProxyAgent } from 'https-proxy-agent'; import { mock } from 'jest-mock-extended'; import type { @@ -322,7 +323,7 @@ describe('Request Helper Functions', () => { url: 'https://example.de/foo/bar', headers: { Host: 'other.host.com' }, }); - expect((axiosOptions.httpsAgent as Agent).options.servername).toEqual('example.de'); + expect((axiosOptions.httpsAgent as HttpsAgent).options.servername).toEqual('example.de'); }); describe('should set SSL certificates', () => { @@ -337,7 +338,7 @@ describe('Request Helper Functions', () => { test('on regular requests', async () => { const axiosOptions = await parseRequestObject(requestObject); - expect((axiosOptions.httpsAgent as Agent).options).toEqual({ + expect((axiosOptions.httpsAgent as HttpsAgent).options).toEqual({ servername: 'example.de', ...agentOptions, noDelay: true, @@ -356,7 +357,7 @@ describe('Request Helper Functions', () => { }; axiosOptions.beforeRedirect!(redirectOptions, mock()); expect(redirectOptions.agent).toEqual(redirectOptions.agents.https); - expect((redirectOptions.agent as Agent).options).toEqual({ + expect((redirectOptions.agent as HttpsAgent).options).toEqual({ servername: 'example.de', ...agentOptions, noDelay: true, @@ -876,12 +877,20 @@ describe('Request Helper Functions', () => { const proxyUrlHttps = 'http://proxy-for-https.com:8080/'; const proxyUrlHttp = 'http://proxy-for-http.com:8080/'; - test('should return a regular agent when no proxy is set', async () => { + test('should return a regular HTTP agent when no proxy is set', async () => { + const { agent, protocol } = getAgentWithProxy({ + targetUrl: baseUrlHttp, + }); + expect(protocol).toEqual('http'); + expect(agent).toBeInstanceOf(HttpAgent); + }); + + test('should return a regular HTTPS agent when no proxy is set', async () => { const { agent, protocol } = getAgentWithProxy({ targetUrl: baseUrlHttps, }); expect(protocol).toEqual('https'); - expect(agent).toBeInstanceOf(Agent); + expect(agent).toBeInstanceOf(HttpsAgent); }); test('should use a proxyConfig object', async () => { @@ -943,7 +952,7 @@ describe('Request Helper Functions', () => { targetUrl: 'https://should-not-proxy.com/foo', }); expect(protocol).toEqual('https'); - expect(agent).toBeInstanceOf(Agent); + expect(agent).toBeInstanceOf(HttpsAgent); }); }); }); diff --git a/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts b/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts index ea3e4b468f..961efafd0e 100644 --- a/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts @@ -19,10 +19,9 @@ import type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from import axios from 'axios'; import crypto, { createHmac } from 'crypto'; import FormData from 'form-data'; -import { IncomingMessage } from 'http'; +import { IncomingMessage, Agent as HttpAgent } from 'http'; import { HttpProxyAgent } from 'http-proxy-agent'; import { type AgentOptions, Agent as HttpsAgent } from 'https'; -import { Agent as HttpAgent } from 'https'; import { HttpsProxyAgent } from 'https-proxy-agent'; import get from 'lodash/get'; import isEmpty from 'lodash/isEmpty';