Releases: sindresorhus/got
4.1.1
4.1.0 - x-www-form-urlencoded
- 7bea9c4 If
bodyis a plain Object, it will be stringified and sent asapplication/x-www-form-urlencoded.
4.0.0
Major release with lots of new stuff! Enjoy!
Promise API
got without callback now returns a promise instead of a stream. The stream API now lives under stream property (look at the end of section).
got('todomvc.com')
.then(function (res) {
console.log(res.body);
})
.catch(function (err) {
console.error(err.response.body);
});In resolve handler you receive a http.response object with body as additional property.
In reject handler we provide an Error object. Unless Error type is RequestError, it will have response property with body property.
This API will be a huge advantage with co and Generators:
var co = require('co');
co(function * () {
try {
var response = yield got('todomvc.com');
console.log(response.body);
} catch (err) {
console.error(err);
}
});You can go even further with destructuring and await from ES7:
async function () {
try {
var {body} = await got('todomvc.com');
console.log(body);
} catch (err) {
console.error(err);
}
}Stream support is preserved, but now under the streams property:
got.stream('todomvc.com').pipe(process.stdout);New Errors
Before 4.0.0 got had one Error class (GotError) with nested stack traces and custom error messages. This was a nice concept, but in production use some edge cases popped out:
- Error stacks are too long.
- Relevant information often were in one or two levels deep (eg.
error.nested.nested). - Errors message are hard to parse for
url.
So we decided to review Errors in new version. In 4.0.0 got now have multiple Error classes for different situations: RequestError, ReadError, ParseError, HTTPError and MaxRedirectsError.
In addition to message and code properties from the original error, the new errors types also provide additional properties (host, hostname, path and method) for logging and debugging.
Infinity-agent removed
Custom agent was removed. This returns the ability to configure or replace global Agent, but also returns low maxSockets value in NodeJS 0.10.x. To fix this you can add this lines at the top of your app (not in reusable modules!):
require('http').globalAgent.maxSockets = Infinity;
require('https').globalAgent.maxSockets = Infinity;Changes
3.3.1
3.3.0
3.2.0
json option now sets Accept header to application/json (if it was not specified in headers)
3.1.0
error event now have additional body and response arguments in callback:
got('http://giggle.com')
.on('error', function (error, body, response) {
console.log(error, body, response);
});3.0.0
Changes
52490b2 New redirect event
This event fired before any redirect with response and nextOptions objects. You can access cookies and store them to be passed with next request in nextOptions.
got('cookie.com')
.on('redirect', function (res, nextOptions) {
nextOptions.headers.cookie = cookie(res);
});Breaking changes
2302a1e Redirects enabled only for GET and HEAD methods
As rfc2616 HTTP 1.1 says:
If the 302 status code is received in response to a request other
than GET or HEAD, the user agent MUST NOT automatically redirect the
request unless it can be confirmed by the user, since this might
change the conditions under which the request was issued.
Now got will not auto-redirect you with unsafe methods (like POST or DELETE), which can cause lots of troubles.
2.9.0
Validation
Options
urlnow acceptshttp.requestoptions as first argument 47da118queryoption added 53df1ca
2.8.0
- Don't mutate the user-supplied options object ae73837
- infinity-agent updated to
2.0.0- which uses backported Agent from Node core c06d741- Every request (in Node 0.10) will now have
Connection: closeheader instead ofConnection: keep-alive.maxSocketsis nowInfinityalways - if you want different value, passnullor new Agent instance.
- Every request (in Node 0.10) will now have

