11import { HttpHandler , HttpRequest , HttpResponse } from "@aws-sdk/protocol-http" ;
22import { buildQueryString } from "@aws-sdk/querystring-builder" ;
33import { HttpHandlerOptions } from "@aws-sdk/types" ;
4- import * as http from "http" ;
5- import * as https from "https" ;
4+ import { Agent as hAgent , request as hRequest } from "http" ;
5+ import { Agent as hsAgent , request as hsRequest , RequestOptions } from "https" ;
66
77import { getTransformedHeaders } from "./get-transformed-headers" ;
88import { setConnectionTimeout } from "./set-connection-timeout" ;
@@ -25,13 +25,13 @@ export interface NodeHttpOptions {
2525 */
2626 socketTimeout ?: number ;
2727
28- httpAgent ?: http . Agent ;
29- httpsAgent ?: https . Agent ;
28+ httpAgent ?: hAgent ;
29+ httpsAgent ?: hsAgent ;
3030}
3131
3232export class NodeHttpHandler implements HttpHandler {
33- private readonly httpAgent : http . Agent ;
34- private readonly httpsAgent : https . Agent ;
33+ private readonly httpAgent : hAgent ;
34+ private readonly httpsAgent : hsAgent ;
3535 private readonly connectionTimeout ?: number ;
3636 private readonly socketTimeout ?: number ;
3737 // Node http handler is hard-coded to http/1.1: https://github.com/nodejs/node/blob/ff5664b83b89c55e4ab5d5f60068fb457f1f5872/lib/_http_server.js#L286
@@ -41,8 +41,8 @@ export class NodeHttpHandler implements HttpHandler {
4141 this . connectionTimeout = connectionTimeout ;
4242 this . socketTimeout = socketTimeout ;
4343 const keepAlive = true ;
44- this . httpAgent = httpAgent || new http . Agent ( { keepAlive } ) ;
45- this . httpsAgent = httpsAgent || new https . Agent ( { keepAlive } ) ;
44+ this . httpAgent = httpAgent || new hAgent ( { keepAlive } ) ;
45+ this . httpsAgent = httpsAgent || new hsAgent ( { keepAlive } ) ;
4646 }
4747
4848 destroy ( ) : void {
@@ -63,7 +63,7 @@ export class NodeHttpHandler implements HttpHandler {
6363 // determine which http(s) client to use
6464 const isSSL = request . protocol === "https:" ;
6565 const queryString = buildQueryString ( request . query || { } ) ;
66- const nodeHttpsOptions : https . RequestOptions = {
66+ const nodeHttpsOptions : RequestOptions = {
6767 headers : request . headers ,
6868 host : request . hostname ,
6969 method : request . method ,
@@ -73,7 +73,8 @@ export class NodeHttpHandler implements HttpHandler {
7373 } ;
7474
7575 // create the http request
76- const req = ( isSSL ? https : http ) . request ( nodeHttpsOptions , ( res ) => {
76+ const requestFunc = isSSL ? hsRequest : hRequest ;
77+ const req = requestFunc ( nodeHttpsOptions , ( res ) => {
7778 const httpResponse = new HttpResponse ( {
7879 statusCode : res . statusCode || - 1 ,
7980 headers : getTransformedHeaders ( res . headers ) ,
0 commit comments