Browse Source

Merge pull request #30 from floatdrop/fix-agent

Set maxSockets to Infinity by default
http2
Sindre Sorhus 10 years ago
parent
commit
939534d31a
  1. 1
      .travis.yml
  2. 17
      index.js
  3. 1
      package.json
  4. 10
      readme.md
  5. 10
      test/test-https.js

1
.travis.yml

@ -1,3 +1,4 @@
language: node_js
node_js:
- '0.10'
- '0.11'

17
index.js

@ -1,13 +1,15 @@
'use strict';
var assign = require('object-assign');
var agent = require('infinity-agent');
var duplexify = require('duplexify');
var http = require('http');
var https = require('https');
var urlLib = require('url');
var zlib = require('zlib');
var duplexify = require('duplexify');
var assign = require('object-assign');
var isReadableStream = require('isstream').isReadable;
var read = require('read-all-stream');
var timeout = require('timed-out');
var isReadableStream = require('isstream').isReadable;
var urlLib = require('url');
var zlib = require('zlib');
function got(url, opts, cb) {
if (typeof opts === 'function') {
@ -55,6 +57,11 @@ function got(url, opts, cb) {
var fn = parsedUrl.protocol === 'https:' ? https : http;
var arg = assign({}, parsedUrl, opts);
// TODO: remove this when Node 0.10 will be deprecated
if (arg.agent === undefined) {
arg.agent = agent(arg);
}
var req = fn.request(arg, function (response) {
var statusCode = response.statusCode;
var res = response;

1
package.json

@ -39,6 +39,7 @@
],
"dependencies": {
"duplexify": "^3.2.0",
"infinity-agent": "^0.1.0",
"isstream": "^0.1.1",
"object-assign": "^2.0.0",
"read-all-stream": "^0.1.0",

10
readme.md

@ -75,6 +75,16 @@ Type: `number`
Milliseconds after which the request will be aborted and an error event with `ETIMEDOUT` code will be emitted.
##### options.agent
[http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) instance.
Node HTTP/HTTPS [Agent in 0.10.35](https://github.com/joyent/node/blob/v0.10.35-release/lib/http.js#L1261) by default limits number of open sockets to 5 — which is a little low. By default got will use `new Agent({maxSockets: Infinity})` like new [Agent in 0.11.14](https://github.com/joyent/node/blob/v0.11.14-release/lib/_http_agent.js#L110).
You can read more about in [why pooling is evil](https://github.com/substack/hyperquest#pooling-is-evil).
To use default [globalAgent](http://nodejs.org/api/http.html#http_http_globalagent) just pass `null` to this option.
##### callback(err, data, response)
###### err

10
test/test-https.js

@ -51,6 +51,16 @@ tape('setup', function (t) {
});
tape('make request to https server', function (t) {
got('https://google.com', {
strictSSL: true
}, function (err, data) {
t.error(err);
t.ok(data);
t.end();
});
});
tape('make request to https server with ca', function (t) {
got(s.url, {
strictSSL: true,
ca: caRootCert,

Loading…
Cancel
Save