Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export HttpAgent as standalone class to avoid namespace clutter and support ESM style imports #119

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ $ npm install agentkeepalive --save

```js
const http = require('http');
const Agent = require('agentkeepalive');
const HttpAgent = require('agentkeepalive').HttpAgent;

const keepaliveAgent = new Agent({
const keepaliveAgent = new HttpAgent({
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000, // active socket keepalive for 60 seconds
Expand Down Expand Up @@ -162,8 +162,8 @@ When server closes connection at unfortunate time ([keep-alive race](https://cod

```js
const http = require('http');
const Agent = require('agentkeepalive');
const agent = new Agent();
const HttpAgent = require('agentkeepalive').HttpAgent;
const agent = new HttpAgent();

const req = http
.get('http://localhost:3000', { agent }, (res) => {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/echo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const Agent = require('../');
const HttpAgent = require('../').HttpAgent;

const agent = new Agent({
const agent = new HttpAgent({
keepAlive: true,
maxSockets: 2,
maxFreeSockets: 2,
Expand Down Expand Up @@ -54,7 +54,7 @@ function showAgentDetail() {
}

const requestPerSocket = agent.createSocketCount && agent.requestFinishedCount / agent.createSocketCount;
console.log('[%s] [worker:%d] Agent(%s,%sms,%s,%s): requests: %d, created: %d, timeout: %d, reqs/socket: %s, pedding requests: %j, alive sockets: %j, free sockets: %j',
console.log('[%s] [worker:%d] HttpAgent(%s,%sms,%s,%s): requests: %d, created: %d, timeout: %d, reqs/socket: %s, pedding requests: %j, alive sockets: %j, free sockets: %j',
Date(), process.pid,
agent.keepAlive && agent.options.keepAlive, agent.keepAliveMsecs,
agent.maxSockets, agent.maxFreeSockets,
Expand Down
6 changes: 3 additions & 3 deletions benchmark/proxy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';

var http = require('http');
var AgentKeepalive = require('../');
var HttpAgent = require('../').HttpAgent;

var maxSockets = parseInt(process.argv[2]) || 10;
var maxFreeSockets = parseInt(process.argv[3]) || maxSockets;
var SERVER = process.argv[4] || '127.0.0.1';

var agentKeepalive = new AgentKeepalive({
var agentKeepalive = new HttpAgent({
keepAlive: true,
maxSockets: maxSockets,
maxFreeSockets: maxFreeSockets,
keepAliveTimeout: 30000,
});
var agentHttp = new AgentKeepalive({
var agentHttp = new HttpAgent({
maxSockets: maxSockets,
keepAlive: false,
});
Expand Down
14 changes: 7 additions & 7 deletions example/agent.js → example/http_agent.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

const http = require('http');
const Agent = require('..');
const HttpAgent = require('..').HttpAgent;

const agent = new Agent();
const http_agent = new HttpAgent();
// https://www.google.com/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8

const options = {
host: 'www.taobao.com',
path: '/',
method: 'GET',
port: 80,
agent,
agent: http_agent,
};

function get() {
Expand All @@ -34,15 +34,15 @@ function get() {
get();

setTimeout(() => {
console.log('keep alive sockets:', agent);
console.log('keep alive sockets:', http_agent);
process.exit();
}, 300000);

let count = 0;
setInterval(() => {
const name = agent.getName(options);
const sockets = agent.sockets[name] || [];
const freeSockets = agent.freeSockets[name] || [];
const name = http_agent.getName(options);
const sockets = http_agent.sockets[name] || [];
const freeSockets = http_agent.freeSockets[name] || [];
console.log('%ss, %s, sockets: %d, destroyed: %s, free sockets: %d, destroyed: %s', ++count,
name, sockets.length, sockets[0] && sockets[0].destroyed,
freeSockets.length, freeSockets[0] && freeSockets[0].destroyed);
Expand Down
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface PlainObject {
[key: string]: any;
}

declare class HttpAgent extends http.Agent {
declare class _HttpAgent extends http.Agent {
constructor(opts?: AgentKeepAlive.HttpOptions);
readonly statusChanged: boolean;
createConnection(options: net.NetConnectOpts, cb?: Function): net.Socket;
Expand All @@ -25,7 +25,10 @@ interface Constants {
SOCKET_REQUEST_FINISHED_COUNT: Symbol;
}

declare class AgentKeepAlive extends HttpAgent {}
/**
* @deprecated instead use `import { HttpAgent } from 'agentkeepalive'; or `const HttpAgent = require('agentkeepalive').HttpAgent;`
*/
declare class AgentKeepAlive extends _HttpAgent {}

declare namespace AgentKeepAlive {
export interface AgentStatus {
Expand All @@ -51,6 +54,7 @@ declare namespace AgentKeepAlive {
export interface HttpOptions extends http.AgentOptions, CommonHttpOption { }
export interface HttpsOptions extends https.AgentOptions, CommonHttpOption { }

export class HttpAgent extends _HttpAgent {}
export class HttpsAgent extends https.Agent {
constructor(opts?: HttpsOptions);
readonly statusChanged: boolean;
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

module.exports = require('./lib/agent');
const HttpAgent = require('./lib/agent');
module.exports = HttpAgent;
module.exports.HttpAgent = HttpAgent;
module.exports.HttpsAgent = require('./lib/https_agent');
module.exports.constants = require('./lib/constants');
37 changes: 21 additions & 16 deletions test/fixtures/agenttest-cert.pem
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIC+jCCAeKgAwIBAgIJAMuPffHFVqVzMA0GCSqGSIb3DQEBCwUAMGExCzAJBgNV
BAYTAlNFMRIwEAYDVQQIDAlTdG9ja2hvbG0xEjAQBgNVBAcMCVN0b2NraG9sbTEL
MAkGA1UEAwwCY2ExHTAbBgkqhkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMB4XDTE3
MTAyMDExMzQwOFoXDTIwMDcxNTExMzQw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asb2CwDe3y0fG
-----END CERTIFICATE-----
43 changes: 28 additions & 15 deletions test/fixtures/agenttest-key.pem
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDlkW4qHfyFy0d892w3zeAzKs15/AOfle0M92fxaYDKEMVf31IL
ySIeJegsAjfmgWvaQb0VH1O+wpxrkp9bkACiEVr5SeSqq8x6gslNN2xUXADw8BQx
aw+fuPSHIuTObU0riLI+z42blSDi+KF2eAYqvD/ChhZfYPQbPE7Y+La5jwIDAQAB
AoGAf4Icb1ZCeUnkRhvjRseZ/LGMeXGpzYznoqkUWblg6FsSVeLjXlp0Ecy6PR9q
TySZdBvJWx8QU8ciPHmu+5trTYwHyTcoj4vZ7yIi5bgJLzIcbKv7zeeiKF+u9+iX
VkLHVdGXWkpw+AsgKZWHfAp9hKcUnSMGW72bU7buUXe0dLkCQQD0xoJKkc4WeLxb
cEqrmks9cIAVxn9QQpqsP5E174Pe6Nq+YPpCiz3vURPb/uTM487NhOX4qwIbmn/F
8lW+4e6rAkEA8Bhl33lMPy3mSD8t+Vl8Nzd96OSl4O9MI1X//hwAK3Unpir0POzb
LprTftVK2w015vFZlWe3Smf3R8pFMllQrQJBAKeX4027Vyf7srvIvteP5URD6u79
4d3KPK0DOSF8xQWy2VLQg4lcXSOml7phY7cFo2sEO5FvRRoxRpr5ucvgVdECQQDf
6tEvvw+WKLeJD6tPzt4jHRTHXF87zdFjbzRlCDY8UXHd7leEbp3n9CtlMYUzkDmC
HfsfdPAja5zajlFEqLmtAkEAsxUKoiBkrJ1TQUmepETKtPNk6eNU8O3Gf484E2Aa
ooNrBva7VvyuOw+OgQKnXZ4sH37uNkS1KQHDp/x5kZX+DQ==
-----END RSA PRIVATE KEY-----
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCsiKbzm3v7DS8N
JPCgEIil4Vdt98D0A56HMD+cZqG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qjtLXoSc
swqI+2+bTEZgubSpjKLHUGbfwSl5NVjBLaoBkVQCGTdslaRLxjtbPkYrQ2q+TnCI
/Wm2g2dM4xKx2wfgp2AokwIAc6VFwIknMQbQY1ULTnmvwXobarzbQIAjAoGBAJcC
+yQ9hJ1mWBRD3crUP/5Vzokq+5MIie3WOWwcUoehN6ig3y50pMN1Kfayq9aXBeJ3
R61W0uC+rJdfD2H30yChQgKlAL8SZdlt2ZVCcA6RSPIQJtRb4Em7ErXZpIdgrGXP
I4TWpGmRkIMGMfP+71zoXAwqTrWbKnAwzV181a1lAoGBAJd7BCyoK6+5BiUzkd0d
asTVaV/BYDWdVrFFr78vjVoscqT66+yBmX3xo65wMHkw0yaRNWfKqE/1yseczQgi
Q3IZCM9YIs+JIGP0mzNzK0apZTiEUwGEDnNvvK41hEMPfLypTBUyAM/mz0E9SyS8
2MTb4gwiIdfW8sgapxzGER7l
-----END PRIVATE KEY-----
52 changes: 26 additions & 26 deletions test/fixtures/ca.key
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDirhR/SK8uxDp3
pZANtV3IeTKFwLdA2G6xNgo7isgCG+OnzEN8zKePSL6vSoUJnYH5KYmNOlO2zc0b
qrvUQWd375WB/zl3MEjJS1+taLxyO+lFlq7fPoB/V4XO+s0l2cA4PyGAkCcisJ5s
LCI2oaxrbjkOPzHC4W05Cj8Svn440kf/2faeHYIdhHGVs36t6nb5d2WnivPvmucp
FOShhK+LFBxL7AQIdoeDdpkjdukT9CnnRT5S1LUq6ReXzjhYqhGU+nmn6GqznpPn
cnZFIRdBQvM3b5BL2NLb5VzglUa2fNYqYGKNGgzj9G/depW8QHOxk3VUJS7vaY0z
PlkTgPO3AgMBAAECggEBAMk4Pnm+y8N37W7ISVfh555N98tDh2jIt3oXvn2cdG9q
0mvhpwbhpNxMdvij7fTbHMVRWglD/YwIpEorBRE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KG4drdi+YAK/tB+YeShC7TiZx9GRKQDyED2eQucc+henLSsdCYJ
RoZP9A4uORc4/sO0PE0mRx/ww06BVa5uaGv2xTeNt9ojRvmV/NwKyTx5NDZoPwM9
yKupukGvTwKBgQCP05xrIoB2J54r31pfH0gyrZGe0g5W+dYrBX0lydeQivL/SipW
+xh7107pM7IAJFj1zwhqXWoJ6qnSxFKEMfza1cw/5LOncIC0ZC3TAkcIqqSg7ILR
7/87ysQs4dNSRNbhyaqoDER56q25/fIt5y5uYSat27PRW57G0ly4X5Tu3wKBgGZJ
A9X/mBrRXely7wtySC5oX9e/bmJBBjz6B7UekCeDPjZKY0pot4MnRR9l1icvYuC4
3hbOPUrFWx4v/XyPTLLq9F7AvEkg3fJuDhHspdqhxxy0BkFDzCjtBMPgiPkWJ4H2
BaEAa/B7UtBYZ5Mu8mYE8U0w4tK9mHgiloo43l71AoGBAKJcF1MuHvddV7SzyK7j
Hf7QdPzsLrPrqH6k9L1yVP1RsouHEgoHh63ot3cZBJEtDodjw9ISoiT4Z1SeGCva
BSXYYjKlwo6ik6kFdy237VJu7XorEmpzhK+K2hoG7azyVJG3imsKCWHW7N75e+Id
A+8fxkdCTHA8dB0pk4Rdth1l
-----END PRIVATE KEY-----
37 changes: 19 additions & 18 deletions test/fixtures/ca.pem
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDPjCCAiYCCQDsuRUq6wfGEDANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJT
RTESMBAGA1UECAwJU3RvY2tob2xtMRIwEAYDVQQHDAlTdG9ja2hvbG0xCzAJBgNV
BAMMAmNhMR0wGwYJKoZIhvcNAQkBFg5jYUBleGFtcGxlLmNvbTAeFw0xNzEwMjAx
MTM0MDhaFw00NTAzMDYxMTM0MDhaMGExCzAJBgNVBAYTAlNFMRIwEAYDVQQIDAlT
dG9ja2hvbG0xEjAQBgNVBAcMCVN0b2NraG9sbTELMAkGA1UEAwwCY2Ex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ExCzAJBgNV
BAYTAlNFMRIwEAYDVQQIDAlTdG9ja2hvbG0xEjAQBgNVBAcMCVN0b2NraG9sbTEL
MAkGA1UEAwwCY2ExHTAbBgkqhkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMIIBIjAN
BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwVsde50ntc8fPzk0k+k+U7WJ/pYP
b+BQhOfqr7pHoKiHsxu/TuieH4xya+g2oJDJWIxnnSTrmXeTUo2ToG+mc/GUVZ5s
RhYX53buT5xUE20qxA2SkBAffxgy7z4Zq28jLSr4/vJtrPa1B4wgPqO+uO+qNuS5
QPBkz9R6mRY96CtJz7Arrg6xMu2mWE3awyiPhVO8bGRyWa6xED6wW9OFbXZRZ4zg
SdVHgFrvbsqRSTGi86KYYIyEGWOlxV1imBFeeTCYLnZrqwvrCN5U6YJzTR7r46Sm
ecWeqSz9DuKVrOxqlgStdXzNG02MVHH+15Z79MrhOyt330WEk9hgm28V9QIDAQAB
oyEwHzAdBgNVHQ4EFgQUHsN9t35DW4U6wZYQ0jOEVIDp7xMwDQYJKoZIhvcNAQEL
BQADggEBAA6peynGrNJfiD9yVvtZTfmnuAUTHlHJ9iUMmugo65J9D27ZgStgGTqE
CwvhoYH+fbeJBB/WrWns48piWYXOUSoyPhCI/hGqGl4uu/d66OBBHLlOE6v2W5x0
EsOxAsTkobcG4y9CBgnoVdzcBuO+wfUFQDZYJkXFYYvK2GxJqJBTlJSqWITLute9
6e8BjytBzZnbI9AIopl+pt+ErMDQfkS1WIHDyg4ER0gpLDrQeJq0JxGuK/d6giYy
hDtsGhz2ibk4DWVxYAlUIPwkvAnDMGW2AwbdAiX7HyqO2OqGwwberhiGZDXqLSoL
LYor6j123IpnraOTz/NQjFMQ7ZyHVAs=
-----END CERTIFICATE-----
4 changes: 2 additions & 2 deletions test/fixtures/genkey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ openssl req -new -x509 -nodes -days 9999 -config ca.cnf -keyout ca.key -out ca.p

# Generate server key
# openssl genrsa -out server.key 2048
openssl genrsa -out agenttest-key.pem 1024
openssl genrsa -out agenttest-key.pem 2048

# Generate a certificate signing request for server.key
# openssl req -new -key server.key -out server.csr
openssl req -new -key agenttest-key.pem -out agenttest.csr -config server.cnf
openssl req -new -key agenttest-key.pem -out agenttest.csr -config server.cnf

# Sign the csr with the ca certificate, generating server.pem
openssl x509 -req -extfile server.cnf -days 999 -passin "pass:password" -extensions v3_req -in agenttest.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out agenttest-cert.pem
Expand Down
18 changes: 8 additions & 10 deletions test/fixtures/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import http from 'http';
import Agent from '../../..';
import assert from 'assert';
import * as http from 'http';
import { constants, HttpAgent, HttpsAgent, HttpOptions, HttpsOptions, AgentStatus } from '../../..';
import * as assert from 'assert';

const constants = Agent.constants;
assert(constants.CREATE_ID);
assert(constants.CREATE_HTTPS_CONNECTION);
assert(constants.CURRENT_ID);

const httpOpt: Agent.HttpOptions = {
const httpOpt: HttpOptions = {
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000, // active socket keepalive for 60 seconds
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
};
const keepaliveAgent = new Agent(httpOpt);
const keepaliveAgent = new HttpAgent(httpOpt);

const options = {
host: 'cnodejs.org',
Expand All @@ -40,19 +39,18 @@ req.end();

setTimeout(() => {
if (keepaliveAgent.statusChanged) {
const httpAgentStatus: Agent.AgentStatus = keepaliveAgent.getCurrentStatus();
const httpAgentStatus: AgentStatus = keepaliveAgent.getCurrentStatus();
console.log('[%s] agent status changed: %j', Date(), httpAgentStatus);
}
}, 2000);

// https
const HttpsAgent = Agent.HttpsAgent;
const httpsOpt: Agent.HttpsOptions = {
const httpsOpt: HttpsOptions = {
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000, // active socket keepalive for 60 seconds
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
};
const keepaliveHttpsAgent = new HttpsAgent(httpsOpt);
const httpsAgentStatus: Agent.AgentStatus = keepaliveHttpsAgent.getCurrentStatus();
const httpsAgentStatus: AgentStatus = keepaliveHttpsAgent.getCurrentStatus();
assert(httpsAgentStatus);
3 changes: 1 addition & 2 deletions test/fixtures/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"skipLibCheck": false,
"skipDefaultLibCheck": false,
"importHelpers": false,
"inlineSourceMap": true,
"esModuleInterop": true
"inlineSourceMap": true
}
}
Loading
Loading