Skip to content

Commit f923fc4

Browse files
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.
1 parent 0addd64 commit f923fc4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/create-http-client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import type { AxiosInstance, CreateHttpClientParams, DefaultOptions } from './ty
1212
// Also enforces toplevel domain specified, no spaces and no protocol
1313
const HOST_REGEX = /^(?!\w+:\/\/)([^\s:]+\.?[^\s:]+)(?::(\d+))?(?!:)$/
1414

15+
function copyHttpClientParams(options: CreateHttpClientParams): CreateHttpClientParams {
16+
const copiedOptions = copy(options)
17+
// httpAgent and httpsAgent cannot be copied because they can contain private fields
18+
copiedOptions.httpAgent = options.httpAgent
19+
copiedOptions.httpsAgent = options.httpsAgent
20+
return copiedOptions
21+
}
22+
1523
/**
1624
* Create pre-configured axios instance
1725
* @private
@@ -124,7 +132,7 @@ export default function createHttpClient(
124132
newParams: Partial<CreateHttpClientParams>,
125133
): AxiosInstance {
126134
return createHttpClient(axios, {
127-
...copy(options),
135+
...copyHttpClientParams(options),
128136
...newParams,
129137
})
130138
}

0 commit comments

Comments
 (0)