File tree 5 files changed +30
-50
lines changed
clients/algoliasearch-client-javascript
client-analytics/utils/requester
client-personalization/utils/requester
client-search/utils/requester
recommend/utils/requester
5 files changed +30
-50
lines changed Original file line number Diff line number Diff line change @@ -5,16 +5,12 @@ import type { EndRequest, Response } from '../types';
5
5
6
6
import { Requester } from './Requester' ;
7
7
8
- export class HttpRequester extends Requester {
9
- private httpAgent : http . Agent ;
10
- private httpsAgent : https . Agent ;
11
-
12
- constructor ( ) {
13
- super ( ) ;
14
- this . httpAgent = new http . Agent ( { keepAlive : true } ) ;
15
- this . httpsAgent = new https . Agent ( { keepAlive : true } ) ;
16
- }
8
+ // Global agents allow us to reuse the TCP protocol with multiple clients
9
+ const agentOptions = { keepAlive : true } ;
10
+ const httpAgent = new http . Agent ( agentOptions ) ;
11
+ const httpsAgent = new https . Agent ( agentOptions ) ;
17
12
13
+ export class HttpRequester extends Requester {
18
14
send ( request : EndRequest ) : Promise < Response > {
19
15
return new Promise ( ( resolve ) => {
20
16
let responseTimeout : NodeJS . Timeout | undefined ;
@@ -24,7 +20,7 @@ export class HttpRequester extends Requester {
24
20
const path =
25
21
url . search === null ? url . pathname : `${ url . pathname } ${ url . search } ` ;
26
22
const options : https . RequestOptions = {
27
- agent : url . protocol === 'https:' ? this . httpsAgent : this . httpAgent ,
23
+ agent : url . protocol === 'https:' ? httpsAgent : httpAgent ,
28
24
hostname : url . hostname ,
29
25
path,
30
26
method : request . method ,
Original file line number Diff line number Diff line change @@ -5,16 +5,12 @@ import type { EndRequest, Response } from '../types';
5
5
6
6
import { Requester } from './Requester' ;
7
7
8
- export class HttpRequester extends Requester {
9
- private httpAgent : http . Agent ;
10
- private httpsAgent : https . Agent ;
11
-
12
- constructor ( ) {
13
- super ( ) ;
14
- this . httpAgent = new http . Agent ( { keepAlive : true } ) ;
15
- this . httpsAgent = new https . Agent ( { keepAlive : true } ) ;
16
- }
8
+ // Global agents allow us to reuse the TCP protocol with multiple clients
9
+ const agentOptions = { keepAlive : true } ;
10
+ const httpAgent = new http . Agent ( agentOptions ) ;
11
+ const httpsAgent = new https . Agent ( agentOptions ) ;
17
12
13
+ export class HttpRequester extends Requester {
18
14
send ( request : EndRequest ) : Promise < Response > {
19
15
return new Promise ( ( resolve ) => {
20
16
let responseTimeout : NodeJS . Timeout | undefined ;
@@ -24,7 +20,7 @@ export class HttpRequester extends Requester {
24
20
const path =
25
21
url . search === null ? url . pathname : `${ url . pathname } ${ url . search } ` ;
26
22
const options : https . RequestOptions = {
27
- agent : url . protocol === 'https:' ? this . httpsAgent : this . httpAgent ,
23
+ agent : url . protocol === 'https:' ? httpsAgent : httpAgent ,
28
24
hostname : url . hostname ,
29
25
path,
30
26
method : request . method ,
Original file line number Diff line number Diff line change @@ -5,16 +5,12 @@ import type { EndRequest, Response } from '../types';
5
5
6
6
import { Requester } from './Requester' ;
7
7
8
- export class HttpRequester extends Requester {
9
- private httpAgent : http . Agent ;
10
- private httpsAgent : https . Agent ;
11
-
12
- constructor ( ) {
13
- super ( ) ;
14
- this . httpAgent = new http . Agent ( { keepAlive : true } ) ;
15
- this . httpsAgent = new https . Agent ( { keepAlive : true } ) ;
16
- }
8
+ // Global agents allow us to reuse the TCP protocol with multiple clients
9
+ const agentOptions = { keepAlive : true } ;
10
+ const httpAgent = new http . Agent ( agentOptions ) ;
11
+ const httpsAgent = new https . Agent ( agentOptions ) ;
17
12
13
+ export class HttpRequester extends Requester {
18
14
send ( request : EndRequest ) : Promise < Response > {
19
15
return new Promise ( ( resolve ) => {
20
16
let responseTimeout : NodeJS . Timeout | undefined ;
@@ -24,7 +20,7 @@ export class HttpRequester extends Requester {
24
20
const path =
25
21
url . search === null ? url . pathname : `${ url . pathname } ${ url . search } ` ;
26
22
const options : https . RequestOptions = {
27
- agent : url . protocol === 'https:' ? this . httpsAgent : this . httpAgent ,
23
+ agent : url . protocol === 'https:' ? httpsAgent : httpAgent ,
28
24
hostname : url . hostname ,
29
25
path,
30
26
method : request . method ,
Original file line number Diff line number Diff line change @@ -5,16 +5,12 @@ import type { EndRequest, Response } from '../types';
5
5
6
6
import { Requester } from './Requester' ;
7
7
8
- export class HttpRequester extends Requester {
9
- private httpAgent : http . Agent ;
10
- private httpsAgent : https . Agent ;
11
-
12
- constructor ( ) {
13
- super ( ) ;
14
- this . httpAgent = new http . Agent ( { keepAlive : true } ) ;
15
- this . httpsAgent = new https . Agent ( { keepAlive : true } ) ;
16
- }
8
+ // Global agents allow us to reuse the TCP protocol with multiple clients
9
+ const agentOptions = { keepAlive : true } ;
10
+ const httpAgent = new http . Agent ( agentOptions ) ;
11
+ const httpsAgent = new https . Agent ( agentOptions ) ;
17
12
13
+ export class HttpRequester extends Requester {
18
14
send ( request : EndRequest ) : Promise < Response > {
19
15
return new Promise ( ( resolve ) => {
20
16
let responseTimeout : NodeJS . Timeout | undefined ;
@@ -24,7 +20,7 @@ export class HttpRequester extends Requester {
24
20
const path =
25
21
url . search === null ? url . pathname : `${ url . pathname } ${ url . search } ` ;
26
22
const options : https . RequestOptions = {
27
- agent : url . protocol === 'https:' ? this . httpsAgent : this . httpAgent ,
23
+ agent : url . protocol === 'https:' ? httpsAgent : httpAgent ,
28
24
hostname : url . hostname ,
29
25
path,
30
26
method : request . method ,
Original file line number Diff line number Diff line change @@ -5,16 +5,12 @@ import type { EndRequest, Response } from '../types';
5
5
6
6
import { Requester } from './Requester' ;
7
7
8
- export class HttpRequester extends Requester {
9
- private httpAgent : http . Agent ;
10
- private httpsAgent : https . Agent ;
11
-
12
- constructor ( ) {
13
- super ( ) ;
14
- this . httpAgent = new http . Agent ( { keepAlive : true } ) ;
15
- this . httpsAgent = new https . Agent ( { keepAlive : true } ) ;
16
- }
8
+ // Global agents allow us to reuse the TCP protocol with multiple clients
9
+ const agentOptions = { keepAlive : true } ;
10
+ const httpAgent = new http . Agent ( agentOptions ) ;
11
+ const httpsAgent = new https . Agent ( agentOptions ) ;
17
12
13
+ export class HttpRequester extends Requester {
18
14
send ( request : EndRequest ) : Promise < Response > {
19
15
return new Promise ( ( resolve ) => {
20
16
let responseTimeout : NodeJS . Timeout | undefined ;
@@ -24,7 +20,7 @@ export class HttpRequester extends Requester {
24
20
const path =
25
21
url . search === null ? url . pathname : `${ url . pathname } ${ url . search } ` ;
26
22
const options : https . RequestOptions = {
27
- agent : url . protocol === 'https:' ? this . httpsAgent : this . httpAgent ,
23
+ agent : url . protocol === 'https:' ? httpsAgent : httpAgent ,
28
24
hostname : url . hostname ,
29
25
path,
30
26
method : request . method ,
You can’t perform that action at this time.
0 commit comments