@@ -113,6 +113,7 @@ export class AWSClientBuilderV3 {
113113 service . middlewareStack . add ( telemetryMiddleware , { step : 'deserialize' } )
114114 service . middlewareStack . add ( loggingMiddleware , { step : 'finalizeRequest' } )
115115 service . middlewareStack . add ( getEndpointMiddleware ( settings ) , { step : 'build' } )
116+ service . middlewareStack . add ( keepAliveMiddleware , { step : 'build' } )
116117 return service
117118 }
118119}
@@ -155,6 +156,9 @@ function getEndpointMiddleware(settings: DevSettings = DevSettings.instance): Bu
155156 overwriteEndpoint ( next , context , settings , args )
156157}
157158
159+ const keepAliveMiddleware : BuildMiddleware < any , any > = ( next : BuildHandler < any , any > ) => async ( args : any ) =>
160+ addKeepAliveHeader ( next , args )
161+
158162export async function emitOnRequest ( next : DeserializeHandler < any , any > , context : HandlerExecutionContext , args : any ) {
159163 if ( ! HttpResponse . isInstance ( args . request ) ) {
160164 return next ( args )
@@ -176,8 +180,9 @@ export async function emitOnRequest(next: DeserializeHandler<any, any>, context:
176180}
177181
178182export async function logOnRequest ( next : FinalizeHandler < any , any > , args : any ) {
183+ const request = args . request
179184 if ( HttpRequest . isInstance ( args . request ) ) {
180- const { hostname, path } = args . request
185+ const { hostname, path } = request
181186 // TODO: omit credentials / sensitive info from the logs.
182187 const input = partialClone ( args . input , 3 )
183188 getLogger ( ) . debug ( `API Request (%s %s): %O` , hostname , path , input )
@@ -191,14 +196,23 @@ export function overwriteEndpoint(
191196 settings : DevSettings ,
192197 args : any
193198) {
194- if ( HttpRequest . isInstance ( args . request ) ) {
195- const serviceId = getServiceId ( context as object )
199+ const request = args . request
200+ if ( HttpRequest . isInstance ( request ) ) {
201+ const serviceId = getServiceId ( context satisfies { clientName ?: string ; commandName ?: string } )
196202 const endpoint = serviceId ? settings . get ( 'endpoints' , { } ) [ serviceId ] : undefined
197203 if ( endpoint ) {
198204 const url = new URL ( endpoint )
199- Object . assign ( args . request , selectFrom ( url , 'hostname' , 'port' , 'protocol' , 'pathname' ) )
200- args . request . path = args . request . pathname
205+ Object . assign ( request , selectFrom ( url , 'hostname' , 'port' , 'protocol' , 'pathname' ) )
206+ request . path = ( request as HttpRequest & { pathname : string } ) . pathname
201207 }
202208 }
203209 return next ( args )
204210}
211+
212+ export function addKeepAliveHeader ( next : BuildHandler < any , any > , args : any ) {
213+ const request = args . request
214+ if ( HttpRequest . isInstance ( request ) ) {
215+ request . headers [ 'Connection' ] = 'keep-alive'
216+ }
217+ return next ( args )
218+ }
0 commit comments