File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed
Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ import httpAgent from "./lib/http-agent" ;
2+ import httpsAgent from "./lib/https-agent" ;
3+
4+ export const http = {
5+ Agent : httpAgent ,
6+ } ;
7+
8+ export const https = {
9+ Agent : httpsAgent ,
10+ } ;
Original file line number Diff line number Diff line change 1+ export default interface clientConfigurationDefault {
2+ /**
3+ * Maximum Socket Number: true if TCP session reuse must be enabled
4+ */
5+ maxSockets ?: boolean ;
6+ }
Original file line number Diff line number Diff line change 1+ import * as http from 'http' ;
2+ import clientConfigurationDefault from './config/default' ;
3+
4+ /**
5+ * @class ClientHttp
6+ * Abstracts the native http.Agent class to enforce common
7+ * networking configuration across components.
8+ */
9+ export default class ClientHttp extends http . Agent {
10+ /**
11+ * The maximum socket configuration defaults to 50.
12+ */
13+ private static maxSocketsConfiguration = Number ( process . env . MAX_SOCKETS ) || 50 ;
14+
15+ /**
16+ * Constructor for the ClientHttp class
17+ *
18+ * @param opts - Custom HTTP Agent options
19+ * @param config - user-defined default configuration du apply
20+ */
21+ constructor (
22+ opts ?: http . AgentOptions ,
23+ config : clientConfigurationDefault = {
24+ maxSockets : true ,
25+ } ,
26+ ) {
27+ // Enforce TCP session reuse configuration, unless explicitely specified.
28+ const defaultConfigurations : http . AgentOptions = { } ;
29+ if ( config . maxSockets ) {
30+ defaultConfigurations . keepAlive = true ;
31+ defaultConfigurations . maxSockets = ClientHttp . maxSocketsConfiguration ;
32+ defaultConfigurations . maxFreeSockets = ClientHttp . maxSocketsConfiguration ;
33+ }
34+ super ( {
35+ ...opts ,
36+ ...defaultConfigurations ,
37+ } ) ;
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ import * as https from 'https' ;
2+ import clientConfigurationDefault from './config/default' ;
3+
4+ /**
5+ * @class ClientHttps
6+ * Abstracts the native https.Agent class to enforce common
7+ * networking configuration across components.
8+ */
9+ export default class ClientHttps extends https . Agent {
10+ /**
11+ * The maximum socket configuration defaults to 50.
12+ */
13+ private static maxSocketsConfiguration = Number ( process . env . MAX_SOCKETS ) || 50 ;
14+
15+ /**
16+ * Constructor for the ClientHttps class
17+ *
18+ * @param opts - Custom HTTPs Agent options
19+ * @param config - user-defined default configuration du apply
20+ */
21+ constructor (
22+ opts ?: https . AgentOptions ,
23+ config : clientConfigurationDefault = {
24+ maxSockets : true ,
25+ } ,
26+ ) {
27+ // Enforce TCP session reuse configuration, unless explicitely specified.
28+ const defaultConfigurations : https . AgentOptions = { } ;
29+ if ( config . maxSockets ) {
30+ defaultConfigurations . keepAlive = true ;
31+ defaultConfigurations . maxSockets = ClientHttps . maxSocketsConfiguration ;
32+ defaultConfigurations . maxFreeSockets = ClientHttps . maxSocketsConfiguration ;
33+ }
34+ super ( {
35+ ...opts ,
36+ ...defaultConfigurations ,
37+ } ) ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments