Skip to content

Commit c424e90

Browse files
committed
feat: Replace agentkeepalive with native Node.js HTTP agents for proxy support
Replace the agentkeepalive dependency with Node.js native http.Agent and https.Agent to enable HTTP proxy support. The native agents support the HTTP_PROXY and HTTPS_PROXY environment variables out of the box, allowing the client to work seamlessly with proxy configurations. This change maintains the same keep-alive functionality while removing an external dependency and adding proxy support capability.
1 parent 5860629 commit c424e90

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

package-lock.json

Lines changed: 1 addition & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@apify/log": "^2.2.6",
6767
"@apify/utilities": "^2.23.2",
6868
"@crawlee/types": "^3.3.0",
69-
"agentkeepalive": "^4.2.1",
7069
"ansi-colors": "^4.1.1",
7170
"async-retry": "^1.3.3",
7271
"axios": "^1.6.7",

src/http_client.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import http from 'node:http';
2+
import https from 'node:https';
13
import os from 'node:os';
24

3-
import KeepAliveAgent from 'agentkeepalive';
45
import type { RetryFunction } from 'async-retry';
56
import retry from 'async-retry';
67
import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
@@ -32,9 +33,9 @@ export class HttpClient {
3233

3334
timeoutMillis: number;
3435

35-
httpAgent?: KeepAliveAgent;
36+
httpAgent?: http.Agent;
3637

37-
httpsAgent?: KeepAliveAgent.HttpsAgent;
38+
httpsAgent?: https.Agent;
3839

3940
axios: AxiosInstance;
4041

@@ -58,11 +59,13 @@ export class HttpClient {
5859
// is for inactive sockets, sometimes the platform would take
5960
// long to process requests and the socket would time-out
6061
// while waiting for the response.
61-
const agentOpts = {
62+
const agentOptions: http.AgentOptions = {
63+
keepAlive: true,
6264
timeout: this.timeoutMillis,
6365
};
64-
this.httpAgent = new KeepAliveAgent(agentOpts);
65-
this.httpsAgent = new KeepAliveAgent.HttpsAgent(agentOpts);
66+
67+
this.httpAgent = new http.Agent(agentOptions);
68+
this.httpsAgent = new https.Agent(agentOptions);
6669
}
6770

6871
this.axios = axios.create({

0 commit comments

Comments
 (0)