This repository was archived by the owner on Feb 5, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ var TransformIterator = require('asynciterator').TransformIterator,
12
12
* It performs request pooling and time-based content negotiation.
13
13
* @param {String } [options.request] The HTTP request module to use
14
14
* @param {String } [options.contentType=* / *] The desired content type of representations
15
+ * @param {integer } [options.concurrentRequests=10] Maximum number of concurrent requests per client
15
16
* @constructor
16
17
*/
17
18
function HttpClient ( options ) {
@@ -27,7 +28,7 @@ function HttpClient(options) {
27
28
'accept-datetime' : options . datetime && options . datetime . toUTCString ( ) ,
28
29
} , _ . identity ) ;
29
30
this . _logger = options . logger || logger ( 'HttpClient' ) ;
30
- this . _maxActiveRequestCount = options . concurrentRequests || 5 ;
31
+ this . _maxActiveRequestCount = options . concurrentRequests || 10 ;
31
32
32
33
// Set up request queue
33
34
this . _requestId = 0 ;
Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ var EventEmitter = require('events').EventEmitter,
8
8
https = require ( 'follow-redirects' ) . https ,
9
9
zlib = require ( 'zlib' ) ;
10
10
11
+ // Try to keep connections open, and set a maximum number of connections per server
12
+ var AGENT_SETTINGS = { keepAlive : true , maxSockets : 5 } ;
13
+ var AGENTS = {
14
+ 'http:' : new http . Agent ( AGENT_SETTINGS ) ,
15
+ 'https:' : new https . Agent ( AGENT_SETTINGS ) ,
16
+ } ;
17
+
18
+ // Decode encoded streams with these decoders
11
19
var DECODERS = { gzip : zlib . createGunzip , deflate : zlib . createInflate } ;
12
20
13
21
// Creates an HTTP request with the given settings
@@ -19,6 +27,7 @@ function createRequest(settings) {
19
27
// Emit the response through a proxy
20
28
var request , requestProxy = new EventEmitter ( ) ,
21
29
requester = settings . protocol === 'http:' ? http : https ;
30
+ settings . agent = AGENTS [ settings . protocol ] ;
22
31
request = requester . request ( settings , function ( response ) {
23
32
response = decode ( response ) ;
24
33
response . setEncoding ( 'utf8' ) ;
You can’t perform that action at this time.
0 commit comments