Skip to content

Releases: sindresorhus/got

v11.8.3

18 Nov 05:02
Compare
Choose a tag to compare

v11.8.2...v11.8.3

v12.0.0-beta.4

12 Aug 07:13
Compare
Choose a tag to compare
v12.0.0-beta.4 Pre-release
Pre-release
  • Fix invalid afterResponse return check cbc8902
  • Clarify retryWithMergedOptions valid hooks (#1832) 15c30ee
  • Add Apify to Showcase (#1828) 3386bf1
  • Add got-scraping to Got plugins in readme (#1823) 7805501
  • Fix https.alpnProtocols not having an effect e1099fb

v12.0.0-beta.3

06 Aug 09:06
Compare
Choose a tag to compare
v12.0.0-beta.3 Pre-release
Pre-release

Bug fixes

Previously Got 12 was freezing the options instead of cloning, but it seems this is too breaking.
Reverted option freezing so the behavior matches Got 11.

v12.0.0-beta.2

04 Aug 21:43
Compare
Choose a tag to compare
v12.0.0-beta.2 Pre-release
Pre-release

v12.0.0-beta.2 introduces more stability fixes! Yay!

Bug fixes

Improvements

  • General code improvements a5dd9aa

Documentation

v12.0.0-beta.1

22 Jul 13:20
Compare
Choose a tag to compare
v12.0.0-beta.1 Pre-release
Pre-release

We are pleased to announce Got v12.0.0 beta 1! 🎉
It's been a year and three months since Got 11 was released, and the latest Got version (v11.8.2) was released just in February ❄️
During that time, we have been working hard on squashing bugs and improving overall experience.

If you find Got useful, you might want to sponsor the Got maintainers.

This package is now pure ESM

Please read this. Also see #1789.

Required Node.js >=14

While working with streams, we encountered more Node.js bugs that needed workarounds.
In order to keep our code clean, we had to drop Node.js v12 as the code would get more messy.
We strongly recommend that you update Node.js to v14 LTS.

HTTP/2 support

Every Node.js release, the native http2 module gets more stable.
Unfortunately there are still some issues on the Node.js side, so we decided to keep HTTP/2 disabled for now.
We may enable it by default in Got v13. It is still possible to turn it on via the http2 option.

To run HTTP/2 requests, it is required to use Node.js v15.10 or above.

Bug fixes

Woah, we possibly couldn't make a release if we didn't fix some bugs!

  • Do not throw on custom stack traces (#1491) 49c16ee
  • Remove automatic content-length on ReadStream (#1510) 472b8ef
  • Fix promise shortcuts in case of error status code (#1543) ff918fb 1107cc6
  • Invert the methodRewriting option 51d88a0
  • Fix url not being reused on retry in rare case (#1487) 462bc63
  • Fix hanging promise on HTTP/2 timeout (#1492) a59fac4
  • Prevent uncaught ParseErrors on initial successful response (#1527) 77df9c3
  • Throw an error when retrying with consumed body (#1507) 62305d7
  • Fix a Node.js 16 bug that hangs Got streams 06a2d3d
  • Fix default pagination handling for empty Link header (#1768) 1e1e506
  • Fix incorrect response.complete when using cache 9e15d88
  • Fix Cannot call end error when request returns a Writable 226cc39
  • Fix Request options not being reused on retry 3c23eea
  • Fix types being not compatible with CommonJS 3c23eea
  • Fix got.paginate does not call init hooks (#1574) 3c23eea
  • Generate a new object when passing options to the native https module (#1567) 3c23eea

Improvements

Breaking changes

Improved option normalization

  • Got exports an Option class that is specifically designed to parse and validate Got options.
    It is made of setters and getters that provide fast normalization and more consistent behavior.

When passing an option does not exist, Got will throw an error. In order to retrieve the options before the error, use error.options.

import got from 'got';

try {
    await got('https://httpbin.org/anything', {
        thisOptionDoesNotExist: true
    });
} catch (error) {
    console.error(error);
    console.error(error.options.url.href);
    // Unexpected option: thisOptionDoesNotExist
    // https://httpbin.org/anything
}
  • The init hook now accepts a second argument: self, which points to an Options instance.

In order to define your own options, you have to move them to options.context in an init hook or store them in options.context directly.

  • The init hooks are ran only when passing an options object explicitly.
- await got('https://example.com'); // this will *not* trigger the init hooks
+ await got('https://example.com', {}); // this *will** trigger init hooks
- got.defaults.options = got.mergeOptions(got.defaults.options, {…});
+ got.defaults.options.merge(…);

This fixes issues like #1450

  • Legacy Url instances are not supported anymore. You need to use WHATWG URL instead.
- await got(string, {port: 8443});
+ const url = new URL(string);
+ url.port = 8443;
+ await got(url);
  • No implicit timeout declaration.
- await got('https://example.com', {timeout: 5000})
+ await got('https://example.com', {timeout: {request: 5000})
  • No implicit retry declaration.
- await got('https://example.com', {retry: 5})
+ await got('https://example.com', {retry: {limit: 5})
  • dnsLookupIpVersion is now a number (4 or 6) or undefined
- await got('https://example.com', {dnsLookupIpVersion: 'ipv4'})
+ await got('https://example.com', {dnsLookupIpVersion: 4})
  • redirectUrls and requestUrl now give URL instances
- request.requestUrl
+ request.requestUrl.origin
+ request.requestUrl.href
+ request.requestUrl.toString()
- request.redirectUrls[0]
+ request.redirectUrls[0].origin
+ request.redirectUrls[0].href
+ request.redirectUrls[0].toString()
  • Renamed request.aborted to request.isAborted
- request.aborted
+ request.isAborted

Reason: consistency with options.isStream.

  • Renamed the lookup option to dnsLookup
- await got('https://example.com', {lookup: cacheable.lookup})
+ await got('https://example.com', {dnsLookup: cacheable.lookup})
  • The beforeRetry hook now accepts only two arguments: error and retryCount
await got('https://example.com', {
    hooks: {
        beforeRetry: [
-            (options, error, retryCount) => {
-                console.log(options, error, retryCount);
-            }
+            (error, retryCount) => {
+                console.log(error.options, error, retryCount);
+            }
        ]
    }
})

The options argument has been removed, however it's still accessible via error.options. All modifications on error.options will be reflected in the next requests (no behavior change, same as with Got 11).

  • The beforeRedirect hook's first argument (options) is now a cloned instance of the Request options.

This was done to make retrieving the original options possible: plainResponse.request.options.

await got('http://szmarczak.com', {
    hooks: {
        beforeRedirect: [
            (options, response) => {
-                console.log(options === response.request.options); //=> true [invalid! our original options were overriden]
+                console.log(options === response.request.options); //=> false [we can access the original options now]
            }
        ]
    }
})
  • The redirect event now takes two arguments in this order: updatedOptions and plainResponse.
- stream.on('redirect', (response, options) => …)
+ stream.on('redirect', (options, response) => …)

Reason: consistency with the beforeRedirect hook.

  • The socketPath option has been removed. Use the unix: protocol instead.
- got('/containers/json', {socketPath: '/var/run/docker.sock'})
+ got('unix:/var/run/docker.sock:/containers/json')
+ got('http://unix:/var/run/docker.sock:/containers/json')
  • The retryWithMergedOptions function in an afterResponse hook no longer returns a Promise.

It now throws RetryError, so this should this should be the last function being executed.
This was done to allow beforeRetry hooks getting called.

  • You can no longer set options.agent to false.
    To do so, you need to define all the options.agent properties: http, https and http2.
await got('https://example.com', {
-    agent: fals...
Read more

v11.8.2

26 Feb 09:43
Compare
Choose a tag to compare
  • Make the dnsCache option lazy (#1529) 3bd245f
    This slightly improves Got startup performance and fixes an issue with Jest.

v11.8.1...v11.8.2

v11.8.1

10 Dec 11:47
Compare
Choose a tag to compare

v11.8.0

20 Oct 17:14
Compare
Choose a tag to compare
  • Fix for sending files with size 0 on stat (#1488) 7acd380
  • beforeRetry allows stream body if different from original (#1501) 3dd2273
  • Set default value for an options object (#1495) 390b145

v11.7.0...v11.8.0

v11.7.0

18 Sep 21:33
Compare
Choose a tag to compare

Improvements

Fixes

  • Fix a regression where body was sent after redirect 88b32ea
  • Fix destructure error on promise.json() c97ce7c
  • Do not ignore userinfo on a redirect to the same origin 52de13b

v11.6.2...v11.7.0

v11.6.2

10 Sep 14:05
Compare
Choose a tag to compare

Bug fixes

  • Inherit the prefixUrl option from parent if it's undefined (#1448) a3da70a
  • Prepare a fix for hanging promise on Node.js 14.10.x 29d4e32
  • Prepare for Node.js 15.0.0 c126ff1

Docs

Tests

  • Downgrade Travis CI Node.js version to 14.9.0 (#1454) 27470b5