Skip to content

Releases: sindresorhus/got

4.1.0 - x-www-form-urlencoded

27 Jul 11:15
Compare
Choose a tag to compare
  • 7bea9c4 If body is a plain Object, it will be stringified and sent as application/x-www-form-urlencoded.

v4.0.0...v4.1.0

4.0.0

25 Jul 07:08
Compare
Choose a tag to compare

Major release with lots of new stuff! Enjoy!

anigif_enhanced-buzz-14210-1427585395-12

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

v3.3.1...v4.0.0

3.3.1

16 Jul 01:22
Compare
Choose a tag to compare
  • 312c80d Don't parse JSON on 204 responses. #78
  • 79f1390 Emit response event only on final request. #75
  • b9c33aa Reselect agent on redirect from HTTP to HTTPS. #80

v3.3.0...v3.3.1

3.3.0

30 Jun 15:51
Compare
Choose a tag to compare
  • 87d98e1 Added content-length header in requests with body.
  • d7a66ba Fallback on pathname option, if no path is present.

v3.2.0...v3.3.0

3.2.0

09 May 07:46
Compare
Choose a tag to compare

json option now sets Accept header to application/json (if it was not specified in headers)

v3.1.0...v3.2.0

3.1.0

09 May 07:44
Compare
Choose a tag to compare

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);
    });

v3.0.0...v3.1.0

3.0.0

06 May 06:38
Compare
Choose a tag to compare

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.

v2.9.0...v3.0.0

2.9.0

26 Apr 16:10
Compare
Choose a tag to compare

angry-bear

Validation

  • url now throws error if not string or object 6b01569
  • Nice error on wrong body option type a0913bc

Options

v2.8.0...v2.9.0

2.8.0

21 Apr 05:45
Compare
Choose a tag to compare
  • 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: close header instead of Connection: keep-alive. maxSockets is now Infinity always - if you want different value, pass null or new Agent instance.

v2.7.2...v2.8.0

2.7.2

08 Apr 19:05
Compare
Choose a tag to compare

Fixed absent nested error on parse error of response.

v2.7.1...v2.7.2