1+ import { parse } from 'url' ;
12import { queue } from 'async' ;
23import * as needle from 'needle' ;
3- import { NeedleResponse , NeedleHttpVerbs , NeedleOptions } from 'needle' ;
44import * as sleep from 'sleep-promise' ;
5+ import { Agent as HttpAgent } from 'http' ;
6+ import { Agent as HttpsAgent } from 'https' ;
7+ import { NeedleResponse , NeedleHttpVerbs , NeedleOptions } from 'needle' ;
8+
59import { logger } from '../common/logger' ;
610import { config } from '../common/config' ;
711import {
@@ -28,6 +32,16 @@ interface HomebaseRequest {
2832const upstreamUrl =
2933 config . INTEGRATION_API || config . DEFAULT_KUBERNETES_UPSTREAM_URL ;
3034
35+ let agent = new HttpAgent ( {
36+ keepAlive : true ,
37+ } ) ;
38+
39+ if ( parse ( upstreamUrl ) . protocol ?. startsWith ( 'https' ) ) {
40+ agent = new HttpsAgent ( {
41+ keepAlive : true ,
42+ } ) ;
43+ }
44+
3145// Async queue wraps around the call to retryRequest in order to limit
3246// the number of requests in flight to Homebase at any one time.
3347const reqQueue = queue ( async function ( req : HomebaseRequest ) {
@@ -227,7 +241,9 @@ async function retryRequest(
227241 const options : NeedleOptions = {
228242 json : true ,
229243 compressed : true ,
244+ agent,
230245 } ;
246+
231247 if ( config . HTTP_PROXY || config . HTTPS_PROXY ) {
232248 options . agent = getProxyAgent ( config , url ) ;
233249 }
0 commit comments