From f923fc444407e9673cdf699302b0a59fd3927b46 Mon Sep 17 00:00:00 2001 From: Jared Jolton <145477871+jjolton-contentful@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:49:06 -0700 Subject: [PATCH] fix: don't copy httpAgent/httpsAgent [EXT-5676] (#526) Users face issues employing custom `httpsAgent`s that utilize private fields. Since these fields are not copyable, they must be excluded from the deep copy that is utilized to ensure we avoid mutating things unnecessarily. --- src/create-http-client.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/create-http-client.ts b/src/create-http-client.ts index 70e6b33..bd65d08 100644 --- a/src/create-http-client.ts +++ b/src/create-http-client.ts @@ -12,6 +12,14 @@ import type { AxiosInstance, CreateHttpClientParams, DefaultOptions } from './ty // Also enforces toplevel domain specified, no spaces and no protocol const HOST_REGEX = /^(?!\w+:\/\/)([^\s:]+\.?[^\s:]+)(?::(\d+))?(?!:)$/ +function copyHttpClientParams(options: CreateHttpClientParams): CreateHttpClientParams { + const copiedOptions = copy(options) + // httpAgent and httpsAgent cannot be copied because they can contain private fields + copiedOptions.httpAgent = options.httpAgent + copiedOptions.httpsAgent = options.httpsAgent + return copiedOptions +} + /** * Create pre-configured axios instance * @private @@ -124,7 +132,7 @@ export default function createHttpClient( newParams: Partial, ): AxiosInstance { return createHttpClient(axios, { - ...copy(options), + ...copyHttpClientParams(options), ...newParams, }) }