Skip to content

Commit

Permalink
Drop infinity-agent
Browse files Browse the repository at this point in the history
Overall it is a bad practice to 'fix' internal modules within the other module.

I think graceful-fs (https://github.com/isaacs/node-graceful-fs#global-patching) is good example, how to do this:

```js
var http = require('http');
var https = requrie('https');

var infinityAgent = require('infinity-agent');
infinityAgent.patch(http);
infinityAgent.patch(https);
```

This will enable global agent tuning in edge cases.

Closes #73 and closes #60
  • Loading branch information
floatdrop committed Jul 15, 2015
1 parent 7bc82b8 commit 63d95b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
28 changes: 1 addition & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var util = require('util');
var zlib = require('zlib');
var querystring = require('querystring');
var objectAssign = require('object-assign');
var infinityAgent = require('infinity-agent');
var duplexify = require('duplexify');
var isStream = require('is-stream');
var readAllStream = require('read-all-stream');
Expand Down Expand Up @@ -35,9 +34,7 @@ function got(url, opts, cb) {
}

opts = objectAssign(
{
protocol: 'http:'
},
{protocol: 'http:'},
typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url,
opts
);
Expand Down Expand Up @@ -110,29 +107,6 @@ function got(url, opts, cb) {
var fn = opts.protocol === 'https:' ? https : http;
var url = urlLib.format(opts);

if (opts.agent === undefined) {
opts.agent = infinityAgent[fn === https ? 'https' : 'http'].globalAgent;

if (process.version.indexOf('v0.10') === 0 && fn === https && (
typeof opts.ca !== 'undefined' ||
typeof opts.cert !== 'undefined' ||
typeof opts.ciphers !== 'undefined' ||
typeof opts.key !== 'undefined' ||
typeof opts.passphrase !== 'undefined' ||
typeof opts.pfx !== 'undefined' ||
typeof opts.rejectUnauthorized !== 'undefined')) {
opts.agent = new infinityAgent.https.Agent({
ca: opts.ca,
cert: opts.cert,
ciphers: opts.ciphers,
key: opts.key,
passphrase: opts.passphrase,
pfx: opts.pfx,
rejectUnauthorized: opts.rejectUnauthorized
});
}
}

var req = fn.request(opts, function (response) {
var statusCode = response.statusCode;
var res = response;
Expand Down
20 changes: 12 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ Type: `number`

Milliseconds after which the request will be aborted and an error event with `ETIMEDOUT` code will be emitted.

###### agent

[http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) instance.

If `undefined` - [`infinity-agent`](https://github.com/floatdrop/infinity-agent) will be used to backport Agent class from Node.js core.

To use default [globalAgent](http://nodejs.org/api/http.html#http_http_globalagent) just pass `null`.

##### callback(error, data, response)

###### error
Expand Down Expand Up @@ -185,6 +177,18 @@ got('todomvc.com', {
```


## Node 0.10

It is a known issue with Node [http.Agent](https://nodejs.org/docs/v0.10.39/api/http.html#http_class_http_agent) and `agent.maxSockets`, which is set to `5`. This can cause low performance of application and (in rare cases) deadlocks. To avoid this you can set it manually:

```js
require('http').globalAgent.maxSockets = Infinity;
require('https').globalAgent.maxSockets = Infinity;
```

This should only ever be done at the top-level application layer.


## Related

- [gh-got](https://github.com/sindresorhus/gh-got) - Convenience wrapper for interacting with the GitHub API
Expand Down

0 comments on commit 63d95b6

Please sign in to comment.