Skip to content

Commit

Permalink
Use node agent with maxSockets set to Infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Jan 1, 2015
1 parent 3ba227a commit b0839a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions index.js
Expand Up @@ -48,15 +48,22 @@ function got(url, opts, cb) {
'accept-encoding': 'gzip,deflate'
}, opts.headers || {});

// Remove socket pooling
// See https://github.com/sindresorhus/got/issues/22
if (!('agent' in opts)) { opts.agent = false; }
opts.maxSockets = opts.maxSockets || Infinity;

var redirectCount = 0;

var get = function (url, opts, cb) {
var parsedUrl = urlLib.parse(url);
var fn = parsedUrl.protocol === 'https:' ? https : http;

var fn;
if (parsedUrl.protocol === 'https:') {
fn = https;
opts.agent = new https.Agent(opts);
} else {
fn = http;
opts.agent = new http.Agent(opts);
}

var arg = assign({}, parsedUrl, opts);

var req = fn.request(arg, function (response) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-redirects.js
Expand Up @@ -17,7 +17,7 @@ s.on('/endless', function (req, res) {
res.writeHead(302, {
location : s.url + '/endless'
});
res.end();
res.end();
});

s.on('/relative', function (req, res) {
Expand Down

0 comments on commit b0839a1

Please sign in to comment.