Skip to content

Commit

Permalink
feat: node-http-handler set default keep-alive to true (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jul 25, 2019
1 parent d8499db commit d709e50
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 28 deletions.
13 changes: 12 additions & 1 deletion packages/client-codecommit-node/CodeCommitConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface CodeCommitConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -182,6 +187,8 @@ export interface CodeCommitResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -335,12 +342,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.utf8Encoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-codecommit-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
targetPrefix: "CodeCommit_20150413",
uid: "codecommit-2015-04-13"
};
export const clientVersion: string = "0.1.0-preview.4";
export const clientVersion: string = "0.1.0-preview.5";
13 changes: 12 additions & 1 deletion packages/client-dynamodb-node/DynamoDBConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface DynamoDBConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface DynamoDBResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -334,12 +341,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.utf8Encoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-dynamodb-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
targetPrefix: "DynamoDB_20120810",
uid: "dynamodb-2012-08-10"
};
export const clientVersion: string = "0.1.0-preview.3";
export const clientVersion: string = "0.1.0-preview.4";
13 changes: 12 additions & 1 deletion packages/client-glacier-node/GlacierConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface GlacierConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface GlacierResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.base64Decoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-glacier-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
signatureVersion: "v4",
uid: "glacier-2012-06-01"
};
export const clientVersion: string = "0.1.0-preview.5";
export const clientVersion: string = "0.1.0-preview.6";
13 changes: 12 additions & 1 deletion packages/client-kms-node/KMSConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface KMSConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface KMSResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -334,12 +341,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.utf8Encoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-kms-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
targetPrefix: "TrentService",
uid: "kms-2014-11-01"
};
export const clientVersion: string = "0.1.0-preview.3";
export const clientVersion: string = "0.1.0-preview.4";
13 changes: 12 additions & 1 deletion packages/client-lambda-node/LambdaConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface LambdaConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface LambdaResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.base64Decoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-lambda-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
signatureVersion: "v4",
uid: "lambda-2015-03-31"
};
export const clientVersion: string = "0.1.0-preview.5";
export const clientVersion: string = "0.1.0-preview.6";
13 changes: 12 additions & 1 deletion packages/client-s3-node/S3Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export interface S3Configuration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -223,6 +228,8 @@ export interface S3ResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -389,12 +396,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.base64Decoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-s3-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
signatureVersion: "s3",
uid: "s3-2006-03-01"
};
export const clientVersion: string = "0.1.0-preview.1";
export const clientVersion: string = "0.1.0-preview.2";
13 changes: 12 additions & 1 deletion packages/client-sqs-node/SQSConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface SQSConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface SQSResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.utf8Encoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-sqs-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
uid: "sqs-2012-11-05",
xmlNamespace: { uri: "http://queue.amazonaws.com/doc/2012-11-05/" }
};
export const clientVersion: string = "0.1.0-preview.5";
export const clientVersion: string = "0.1.0-preview.6";
13 changes: 12 additions & 1 deletion packages/client-xray-node/XRayConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export interface XRayConfiguration {
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;

/**
* 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.
*/
keepAlive?: boolean;

/**
* The maximum number of redirects to follow for a service request. Set to `0` to disable retries.
*/
Expand Down Expand Up @@ -181,6 +186,8 @@ export interface XRayResolvedConfiguration

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;
Expand Down Expand Up @@ -337,12 +344,16 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
configuration.base64Decoder
)
},
keepAlive: {
defaultValue: true
},
_user_injected_http_handler: {
defaultProvider: (configuration: { httpHandler?: any }) =>
!configuration.httpHandler
},
httpHandler: {
defaultProvider: () => new __aws_sdk_node_http_handler.NodeHttpHandler()
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-xray-node/model/ServiceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const ServiceMetadata: _ServiceMetadata_ = {
signatureVersion: "v4",
uid: "xray-2016-04-12"
};
export const clientVersion: string = "0.1.0-preview.5";
export const clientVersion: string = "0.1.0-preview.6";
16 changes: 12 additions & 4 deletions packages/node-http-handler/src/node-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ import { setSocketTimeout } from "./set-socket-timeout";
import { writeRequestBody } from "./write-request-body";

export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
constructor(private readonly httpOptions: NodeHttpOptions = {}) {}
private readonly httpAgent: http.Agent;
private readonly httpsAgent: https.Agent;

constructor(private readonly httpOptions: NodeHttpOptions = {}) {
const { keepAlive } = httpOptions;
this.httpAgent = new http.Agent({ keepAlive });
this.httpsAgent = new https.Agent({ keepAlive });
}

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

handle(
Expand All @@ -43,7 +50,8 @@ export class NodeHttpHandler implements HttpHandler<Readable, NodeHttpOptions> {
host: request.hostname,
method: request.method,
path: path,
port: request.port
port: request.port,
agent: isSSL ? this.httpsAgent : this.httpAgent
};

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit d709e50

Please sign in to comment.