Skip to content

Commit

Permalink
chore: default to connection keep-alive unless set by user
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Oct 28, 2024
1 parent d79b6bc commit ad733dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/base/BaseTwilio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace Twilio {
process.env.TWILIO_LOG_LEVEL;

this.timeout = this.opts.timeout;
this.keepAlive = this.opts.keepAlive || false;
this.keepAlive = this.opts.keepAlive;
this.keepAliveMsecs = this.opts.keepAliveMsecs;
this.maxSockets = this.opts.maxSockets;
this.maxTotalSockets = this.opts.maxTotalSockets;
Expand Down
11 changes: 5 additions & 6 deletions src/base/RequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class RequestClient {
autoRetry: boolean;
maxRetryDelay: number;
maxRetries: number;
keepAlive: boolean;

/**
* Make http request
Expand All @@ -97,11 +98,12 @@ class RequestClient {
this.autoRetry = opts.autoRetry || false;
this.maxRetryDelay = opts.maxRetryDelay || DEFAULT_MAX_RETRY_DELAY;
this.maxRetries = opts.maxRetries || DEFAULT_MAX_RETRIES;
this.keepAlive = opts.keepAlive !== false;

// construct an https agent
let agentOpts: https.AgentOptions = {
timeout: this.defaultTimeout,
keepAlive: opts.keepAlive,
keepAlive: this.keepAlive,
keepAliveMsecs: opts.keepAliveMsecs,
maxSockets: opts.maxSockets || DEFAULT_MAX_SOCKETS, // no of sockets open per host
maxTotalSockets: opts.maxTotalSockets || DEFAULT_MAX_TOTAL_SOCKETS, // no of sockets open in total
Expand Down Expand Up @@ -168,11 +170,8 @@ class RequestClient {

var headers = opts.headers || {};

if (!headers.Connection && !headers.connection && opts.forever) {
headers.Connection = "keep-alive";
} else if (!headers.Connection && !headers.connection) {
headers.Connection = "close";
}
if (!headers.Connection && !headers.connection)
headers.Connection = this.keepAlive ? "keep-alive" : "close";

let auth = undefined;

Expand Down

0 comments on commit ad733dc

Please sign in to comment.