Browse Source

Quick shims

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
16f93eaff1
  1. 21
      index.js
  2. 3
      package.json
  3. 6
      readme.md

21
index.js

@ -128,14 +128,8 @@ function asCallback(opts, cb) {
} }
function asPromise(opts) { function asPromise(opts) {
var resolve, reject; var promise = new pinkiePromise(function (resolve, reject) {
asCallback(opts, function (err, data, response) {
var promise = new pinkiePromise(function (_resolve, _reject) {
resolve = _resolve;
reject = _reject;
});
var cb = function (err, data, response) {
response.body = data; response.body = data;
if (err) { if (err) {
@ -145,9 +139,9 @@ function asPromise(opts) {
} }
resolve(response); resolve(response);
}; });
});
asCallback(opts, cb);
return promise; return promise;
} }
@ -203,9 +197,7 @@ function normalizeArguments(url, opts) {
} }
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
); );
@ -261,7 +253,8 @@ function got(url, opts, cb) {
opts = normalizeArguments(url, opts); opts = normalizeArguments(url, opts);
if (cb) { if (cb) {
return asCallback(opts, cb); asCallback(opts, cb);
return;
} }
return asPromise(opts); return asPromise(opts);

3
package.json

@ -20,8 +20,7 @@
"node": ">=0.10.0" "node": ">=0.10.0"
}, },
"scripts": { "scripts": {
"test": "tap test/test-*.js", "test": "tap test/test-*.js"
"coverage": "istanbul cover tape --report html -- test/test-*.js"
}, },
"files": [ "files": [
"index.js" "index.js"

6
readme.md

@ -186,16 +186,16 @@ got('todomvc.com', {
``` ```
## Node 0.10 ## Node 0.10.x
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: It is a known issue with old good Node 0.10.x [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 ```js
require('http').globalAgent.maxSockets = Infinity; require('http').globalAgent.maxSockets = Infinity;
require('https').globalAgent.maxSockets = Infinity; require('https').globalAgent.maxSockets = Infinity;
``` ```
This should only ever be done at the top-level application layer. This should only ever be done if you have Node version 0.10.x and at the top-level application layer.
## Related ## Related

Loading…
Cancel
Save