Browse Source

Quick shims

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

35
index.js

@ -128,26 +128,20 @@ function asCallback(opts, cb) {
}
function asPromise(opts) {
var resolve, reject;
var promise = new pinkiePromise(function (resolve, reject) {
asCallback(opts, function (err, data, response) {
response.body = data;
var promise = new pinkiePromise(function (_resolve, _reject) {
resolve = _resolve;
reject = _reject;
});
var cb = function (err, data, response) {
response.body = data;
if (err) {
err.response = response;
reject(err);
return;
}
if (err) {
err.response = response;
reject(err);
return;
}
resolve(response);
};
resolve(response);
});
});
asCallback(opts, cb);
return promise;
}
@ -203,9 +197,7 @@ function normalizeArguments(url, opts) {
}
opts = objectAssign(
{
protocol: 'http:'
},
{protocol: 'http:'},
typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url,
opts
);
@ -261,7 +253,8 @@ function got(url, opts, cb) {
opts = normalizeArguments(url, opts);
if (cb) {
return asCallback(opts, cb);
asCallback(opts, cb);
return;
}
return asPromise(opts);

3
package.json

@ -20,8 +20,7 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "tap test/test-*.js",
"coverage": "istanbul cover tape --report html -- test/test-*.js"
"test": "tap test/test-*.js"
},
"files": [
"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
require('http').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

Loading…
Cancel
Save