@@ -7,17 +7,17 @@ import {
77 HttpHandlerOptions ,
88 HttpRequest ,
99 HttpResponse ,
10- NodeHttpOptions
10+ NodeHttp2Options
1111} from "@aws-sdk/types" ;
1212
1313import { writeRequestBody } from "./write-request-body" ;
1414import { getTransformedHeaders } from "./get-transformed-headers" ;
1515
1616export class NodeHttp2Handler
17- implements HttpHandler < Readable , NodeHttpOptions > {
17+ implements HttpHandler < Readable , NodeHttp2Options > {
1818 private readonly connectionPool : Map < string , ClientHttp2Session > ;
1919
20- constructor ( private readonly httpOptions : NodeHttpOptions = { } ) {
20+ constructor ( private readonly http2Options : NodeHttp2Options = { } ) {
2121 this . connectionPool = new Map < string , ClientHttp2Session > ( ) ;
2222 }
2323
@@ -33,8 +33,6 @@ export class NodeHttp2Handler
3333 { abortSignal } : HttpHandlerOptions
3434 ) : Promise < HttpResponse < Readable > > {
3535 return new Promise ( ( resolve , reject ) => {
36- const { connectionTimeout, socketTimeout } = this . httpOptions ;
37-
3836 // if the request was already aborted, prevent doing extra work
3937 if ( abortSignal && abortSignal . aborted ) {
4038 const abortError = new Error ( "Request aborted" ) ;
@@ -76,16 +74,19 @@ export class NodeHttp2Handler
7674 }
7775
7876 private getSession ( authority : string ) : ClientHttp2Session {
79- const existingSession = this . connectionPool . get ( authority ) ;
77+ const connectionPool = this . connectionPool ;
78+ const existingSession = connectionPool . get ( authority ) ;
8079 if ( existingSession ) return existingSession ;
8180
8281 const newSession = connect ( authority ) ;
83- this . connectionPool . set ( authority , newSession ) ;
84- if ( this . httpOptions . connectionTimeout ) {
85- newSession . setTimeout (
86- this . httpOptions . connectionTimeout ,
87- this . connectionPool . delete . bind ( this . connectionPool , authority )
88- ) ;
82+ connectionPool . set ( authority , newSession ) ;
83+
84+ const { sessionTimeout } = this . http2Options ;
85+ if ( sessionTimeout ) {
86+ newSession . setTimeout ( sessionTimeout , ( ) => {
87+ newSession . close ( ) ;
88+ connectionPool . delete ( authority ) ;
89+ } ) ;
8990 }
9091 return newSession ;
9192 }
0 commit comments