File tree 2 files changed +9
-8
lines changed
2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ describe('basics', () => {
11
11
_http . dispose ( )
12
12
} )
13
13
14
+ it . each ( [ true , false ] ) ( 'creates Agent with keepAlive %s' , keepAlive => {
15
+ const http = new httpm . HttpClient ( 'http-client-tests' , [ ] , { keepAlive} )
16
+ const agent = http . getAgent ( 'http://postman-echo.com' )
17
+ expect ( agent ) . toHaveProperty ( 'keepAlive' , keepAlive )
18
+ } )
19
+
14
20
it ( 'does basic http get request with keepAlive true' , async ( ) => {
15
21
const res : httpm . HttpClientResponse = await _http . get (
16
22
'http://postman-echo.com/get'
Original file line number Diff line number Diff line change @@ -649,7 +649,7 @@ export class HttpClient {
649
649
agent = this . _proxyAgent
650
650
}
651
651
652
- if ( this . _keepAlive && ! useProxy ) {
652
+ if ( ! useProxy ) {
653
653
agent = this . _agent
654
654
}
655
655
@@ -690,18 +690,13 @@ export class HttpClient {
690
690
this . _proxyAgent = agent
691
691
}
692
692
693
- // if reusing agent across request and tunneling agent isn't assigned create a new agent
694
- if ( this . _keepAlive && ! agent ) {
693
+ // if tunneling agent isn't assigned create a new agent
694
+ if ( ! agent ) {
695
695
const options = { keepAlive : this . _keepAlive , maxSockets}
696
696
agent = usingSsl ? new https . Agent ( options ) : new http . Agent ( options )
697
697
this . _agent = agent
698
698
}
699
699
700
- // if not using private agent and tunnel agent isn't setup then use global agent
701
- if ( ! agent ) {
702
- agent = usingSsl ? https . globalAgent : http . globalAgent
703
- }
704
-
705
700
if ( usingSsl && this . _ignoreSslError ) {
706
701
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
707
702
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
You can’t perform that action at this time.
0 commit comments