Skip to content

Commit d709e50

Browse files
authored
feat: node-http-handler set default keep-alive to true (#307)
1 parent d8499db commit d709e50

File tree

20 files changed

+176
-28
lines changed

20 files changed

+176
-28
lines changed

Diff for: packages/client-codecommit-node/CodeCommitConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface CodeCommitConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -182,6 +187,8 @@ export interface CodeCommitResolvedConfiguration
182187

183188
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
184189

190+
keepAlive: boolean;
191+
185192
maxRedirects: number;
186193

187194
maxRetries: number;
@@ -335,12 +342,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
335342
configuration.utf8Encoder
336343
)
337344
},
345+
keepAlive: {
346+
defaultValue: true
347+
},
338348
_user_injected_http_handler: {
339349
defaultProvider: (configuration: { httpHandler?: any }) =>
340350
!configuration.httpHandler
341351
},
342352
httpHandler: {
343-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
353+
defaultProvider: (configuration: { keepAlive: boolean }) =>
354+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
344355
},
345356
handler: {
346357
defaultProvider: (configuration: {

Diff for: packages/client-codecommit-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
1212
targetPrefix: "CodeCommit_20150413",
1313
uid: "codecommit-2015-04-13"
1414
};
15-
export const clientVersion: string = "0.1.0-preview.4";
15+
export const clientVersion: string = "0.1.0-preview.5";

Diff for: packages/client-dynamodb-node/DynamoDBConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface DynamoDBConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface DynamoDBResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -334,12 +341,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
334341
configuration.utf8Encoder
335342
)
336343
},
344+
keepAlive: {
345+
defaultValue: true
346+
},
337347
_user_injected_http_handler: {
338348
defaultProvider: (configuration: { httpHandler?: any }) =>
339349
!configuration.httpHandler
340350
},
341351
httpHandler: {
342-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
352+
defaultProvider: (configuration: { keepAlive: boolean }) =>
353+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
343354
},
344355
handler: {
345356
defaultProvider: (configuration: {

Diff for: packages/client-dynamodb-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
1212
targetPrefix: "DynamoDB_20120810",
1313
uid: "dynamodb-2012-08-10"
1414
};
15-
export const clientVersion: string = "0.1.0-preview.3";
15+
export const clientVersion: string = "0.1.0-preview.4";

Diff for: packages/client-glacier-node/GlacierConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface GlacierConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface GlacierResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
337344
configuration.base64Decoder
338345
)
339346
},
347+
keepAlive: {
348+
defaultValue: true
349+
},
340350
_user_injected_http_handler: {
341351
defaultProvider: (configuration: { httpHandler?: any }) =>
342352
!configuration.httpHandler
343353
},
344354
httpHandler: {
345-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
355+
defaultProvider: (configuration: { keepAlive: boolean }) =>
356+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
346357
},
347358
handler: {
348359
defaultProvider: (configuration: {

Diff for: packages/client-glacier-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
99
signatureVersion: "v4",
1010
uid: "glacier-2012-06-01"
1111
};
12-
export const clientVersion: string = "0.1.0-preview.5";
12+
export const clientVersion: string = "0.1.0-preview.6";

Diff for: packages/client-kms-node/KMSConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface KMSConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface KMSResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -334,12 +341,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
334341
configuration.utf8Encoder
335342
)
336343
},
344+
keepAlive: {
345+
defaultValue: true
346+
},
337347
_user_injected_http_handler: {
338348
defaultProvider: (configuration: { httpHandler?: any }) =>
339349
!configuration.httpHandler
340350
},
341351
httpHandler: {
342-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
352+
defaultProvider: (configuration: { keepAlive: boolean }) =>
353+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
343354
},
344355
handler: {
345356
defaultProvider: (configuration: {

Diff for: packages/client-kms-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
1212
targetPrefix: "TrentService",
1313
uid: "kms-2014-11-01"
1414
};
15-
export const clientVersion: string = "0.1.0-preview.3";
15+
export const clientVersion: string = "0.1.0-preview.4";

Diff for: packages/client-lambda-node/LambdaConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface LambdaConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface LambdaResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
337344
configuration.base64Decoder
338345
)
339346
},
347+
keepAlive: {
348+
defaultValue: true
349+
},
340350
_user_injected_http_handler: {
341351
defaultProvider: (configuration: { httpHandler?: any }) =>
342352
!configuration.httpHandler
343353
},
344354
httpHandler: {
345-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
355+
defaultProvider: (configuration: { keepAlive: boolean }) =>
356+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
346357
},
347358
handler: {
348359
defaultProvider: (configuration: {

Diff for: packages/client-lambda-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
99
signatureVersion: "v4",
1010
uid: "lambda-2015-03-31"
1111
};
12-
export const clientVersion: string = "0.1.0-preview.5";
12+
export const clientVersion: string = "0.1.0-preview.6";

Diff for: packages/client-s3-node/S3Configuration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface S3Configuration {
8383
*/
8484
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
8585

86+
/**
87+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
88+
*/
89+
keepAlive?: boolean;
90+
8691
/**
8792
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
8893
*/
@@ -223,6 +228,8 @@ export interface S3ResolvedConfiguration
223228

224229
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
225230

231+
keepAlive: boolean;
232+
226233
maxRedirects: number;
227234

228235
maxRetries: number;
@@ -389,12 +396,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
389396
configuration.base64Decoder
390397
)
391398
},
399+
keepAlive: {
400+
defaultValue: true
401+
},
392402
_user_injected_http_handler: {
393403
defaultProvider: (configuration: { httpHandler?: any }) =>
394404
!configuration.httpHandler
395405
},
396406
httpHandler: {
397-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
407+
defaultProvider: (configuration: { keepAlive: boolean }) =>
408+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
398409
},
399410
handler: {
400411
defaultProvider: (configuration: {

Diff for: packages/client-s3-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
1010
signatureVersion: "s3",
1111
uid: "s3-2006-03-01"
1212
};
13-
export const clientVersion: string = "0.1.0-preview.1";
13+
export const clientVersion: string = "0.1.0-preview.2";

Diff for: packages/client-sqs-node/SQSConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface SQSConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface SQSResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
337344
configuration.utf8Encoder
338345
)
339346
},
347+
keepAlive: {
348+
defaultValue: true
349+
},
340350
_user_injected_http_handler: {
341351
defaultProvider: (configuration: { httpHandler?: any }) =>
342352
!configuration.httpHandler
343353
},
344354
httpHandler: {
345-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
355+
defaultProvider: (configuration: { keepAlive: boolean }) =>
356+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
346357
},
347358
handler: {
348359
defaultProvider: (configuration: {

Diff for: packages/client-sqs-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
1111
uid: "sqs-2012-11-05",
1212
xmlNamespace: { uri: "http://queue.amazonaws.com/doc/2012-11-05/" }
1313
};
14-
export const clientVersion: string = "0.1.0-preview.5";
14+
export const clientVersion: string = "0.1.0-preview.6";

Diff for: packages/client-xray-node/XRayConfiguration.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface XRayConfiguration {
6767
*/
6868
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
6969

70+
/**
71+
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
72+
*/
73+
keepAlive?: boolean;
74+
7075
/**
7176
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
7277
*/
@@ -181,6 +186,8 @@ export interface XRayResolvedConfiguration
181186

182187
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
183188

189+
keepAlive: boolean;
190+
184191
maxRedirects: number;
185192

186193
maxRetries: number;
@@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
337344
configuration.base64Decoder
338345
)
339346
},
347+
keepAlive: {
348+
defaultValue: true
349+
},
340350
_user_injected_http_handler: {
341351
defaultProvider: (configuration: { httpHandler?: any }) =>
342352
!configuration.httpHandler
343353
},
344354
httpHandler: {
345-
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
355+
defaultProvider: (configuration: { keepAlive: boolean }) =>
356+
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
346357
},
347358
handler: {
348359
defaultProvider: (configuration: {

Diff for: packages/client-xray-node/model/ServiceMetadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
99
signatureVersion: "v4",
1010
uid: "xray-2016-04-12"
1111
};
12-
export const clientVersion: string = "0.1.0-preview.5";
12+
export const clientVersion: string = "0.1.0-preview.6";

Diff for: packages/node-http-handler/src/node-http-handler.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ import { setSocketTimeout } from "./set-socket-timeout";
1515
import { writeRequestBody } from "./write-request-body";
1616

1717
export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
18-
constructor(private readonly httpOptions: NodeHttpOptions = {}) {}
18+
private readonly httpAgent: http.Agent;
19+
private readonly httpsAgent: https.Agent;
20+
21+
constructor(private readonly httpOptions: NodeHttpOptions = {}) {
22+
const { keepAlive } = httpOptions;
23+
this.httpAgent = new http.Agent({ keepAlive });
24+
this.httpsAgent = new https.Agent({ keepAlive });
25+
}
1926

2027
destroy(): void {
21-
// pass for now, but this may destroy the underlying agent in the future
22-
// if we decide to enable keep-alive by default.
28+
this.httpAgent.destroy();
29+
this.httpsAgent.destroy();
2330
}
2431

2532
handle(
@@ -43,7 +50,8 @@ export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
4350
host: request.hostname,
4451
method: request.method,
4552
path: path,
46-
port: request.port
53+
port: request.port,
54+
agent: isSSL ? this.httpsAgent : this.httpAgent
4755
};
4856

4957
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)