Browse Source

Drop infinity-agent

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
http2
Vsevolod Strukchinsky 10 years ago
parent
commit
63d95b6316
  1. 28
      index.js
  2. 20
      readme.md

28
index.js

@ -6,7 +6,6 @@ var util = require('util');
var zlib = require('zlib'); var zlib = require('zlib');
var querystring = require('querystring'); var querystring = require('querystring');
var objectAssign = require('object-assign'); var objectAssign = require('object-assign');
var infinityAgent = require('infinity-agent');
var duplexify = require('duplexify'); var duplexify = require('duplexify');
var isStream = require('is-stream'); var isStream = require('is-stream');
var readAllStream = require('read-all-stream'); var readAllStream = require('read-all-stream');
@ -35,9 +34,7 @@ function got(url, opts, cb) {
} }
opts = objectAssign( opts = objectAssign(
{ {protocol: 'http:'},
protocol: 'http:'
},
typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url, typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url,
opts opts
); );
@ -110,29 +107,6 @@ function got(url, opts, cb) {
var fn = opts.protocol === 'https:' ? https : http; var fn = opts.protocol === 'https:' ? https : http;
var url = urlLib.format(opts); 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 req = fn.request(opts, function (response) {
var statusCode = response.statusCode; var statusCode = response.statusCode;
var res = response; var res = response;

20
readme.md

@ -102,14 +102,6 @@ Type: `number`
Milliseconds after which the request will be aborted and an error event with `ETIMEDOUT` code will be emitted. 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) ##### callback(error, data, response)
###### error ###### error
@ -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 ## Related
- [gh-got](https://github.com/sindresorhus/gh-got) - Convenience wrapper for interacting with the GitHub API - [gh-got](https://github.com/sindresorhus/gh-got) - Convenience wrapper for interacting with the GitHub API

Loading…
Cancel
Save