got
Advanced tools
Comparing version 2.7.2 to 2.8.0
43
index.js
@@ -8,18 +8,18 @@ 'use strict'; | ||
var objectAssign = require('object-assign'); | ||
var agent = require('infinity-agent'); | ||
var infinityAgent = require('infinity-agent'); | ||
var duplexify = require('duplexify'); | ||
var isStream = require('is-stream'); | ||
var read = require('read-all-stream'); | ||
var timeout = require('timed-out'); | ||
var readAllStream = require('read-all-stream'); | ||
var timedOut = require('timed-out'); | ||
var prependHttp = require('prepend-http'); | ||
var lowercaseKeys = require('lowercase-keys'); | ||
var status = require('statuses'); | ||
var NestedError = require('nested-error-stacks'); | ||
var statuses = require('statuses'); | ||
var NestedErrorStacks = require('nested-error-stacks'); | ||
function GotError(message, nested) { | ||
NestedError.call(this, message, nested); | ||
NestedErrorStacks.call(this, message, nested); | ||
objectAssign(this, nested, {nested: this.nested}); | ||
} | ||
util.inherits(GotError, NestedError); | ||
util.inherits(GotError, NestedErrorStacks); | ||
GotError.prototype.name = 'GotError'; | ||
@@ -76,5 +76,16 @@ | ||
// TODO: remove this when Node 0.10 will be deprecated | ||
if (arg.agent === undefined) { | ||
arg.agent = agent(arg); | ||
arg.agent = infinityAgent[fn === https ? 'https' : 'http'].globalAgent; | ||
// TODO: remove this when Node 0.10 will be deprecated | ||
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')) { | ||
arg.agent = new (infinityAgent.https.Agent)(opts); | ||
} | ||
} | ||
@@ -91,3 +102,3 @@ | ||
// redirect | ||
if (status.redirect[statusCode] && 'location' in res.headers) { | ||
if (statuses.redirect[statusCode] && 'location' in res.headers) { | ||
res.resume(); // Discard response | ||
@@ -111,4 +122,4 @@ | ||
if (statusCode < 200 || statusCode > 299) { | ||
read(res, encoding, function (err, data) { | ||
err = new GotError(url + ' response code is ' + statusCode + ' (' + status[statusCode] + ')', err); | ||
readAllStream(res, encoding, function (err, data) { | ||
err = new GotError(url + ' response code is ' + statusCode + ' (' + statuses[statusCode] + ')', err); | ||
err.code = statusCode; | ||
@@ -135,3 +146,3 @@ | ||
read(res, encoding, function (err, data) { | ||
readAllStream(res, encoding, function (err, data) { | ||
if (err) { | ||
@@ -154,3 +165,3 @@ err = new GotError('Reading ' + url + ' response failed', err); | ||
if (opts.timeout) { | ||
timeout(req, opts.timeout); | ||
timedOut(req, opts.timeout); | ||
} | ||
@@ -203,5 +214,3 @@ | ||
got[el] = function (url, opts, cb) { | ||
opts = opts || {}; | ||
opts.method = el.toUpperCase(); | ||
return got(url, opts, cb); | ||
return got(url, objectAssign({}, opts, {method: el.toUpperCase()}), cb); | ||
}; | ||
@@ -208,0 +217,0 @@ }); |
{ | ||
"name": "got", | ||
"version": "2.7.2", | ||
"version": "2.8.0", | ||
"description": "Simplified HTTP/HTTPS requests", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
"duplexify": "^3.2.0", | ||
"infinity-agent": "^1.0.0", | ||
"infinity-agent": "^2.0.0", | ||
"is-stream": "^1.0.0", | ||
@@ -46,0 +46,0 @@ "lowercase-keys": "^1.0.0", |
@@ -91,6 +91,4 @@ # got [![Build Status](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got) | ||
Node HTTP/HTTPS Agent in [0.10](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 too low. If `options.agent` is not defined `got` will use [infinity-agent](https://github.com/floatdrop/infinity-agent) to backport `defaultMaxSockets` from [0.12](https://github.com/joyent/node/blob/v0.12.2-release/lib/_http_agent.js#L110). | ||
If `undefined` - [`infinity-agent`](https://github.com/floatdrop/infinity-agent) will be used to backport Agent class from Node core. | ||
[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. | ||
@@ -163,4 +161,9 @@ | ||
## Related | ||
* [`gh-got`](https://github.com/sindresorhus/gh-got) - Convenience wrapper for interacting with the GitHub API | ||
* [`got-promise`](https://github.com/floatdrop/got-promise) - Promise wrapper | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
10223
175
168
+ Addedinfinity-agent@2.0.3(transitive)
- Removedinfinity-agent@1.0.2(transitive)
Updatedinfinity-agent@^2.0.0