chore(deps): update dependency got to v16 - autoclosed #15

Closed
renovate-bot wants to merge 1 commit from renovate/got-16.x into main
Member

This PR contains the following updates:

Package Change Age Confidence
got 11.8.5 → 16.2.0 age confidence

Release Notes

sindresorhus/got (got)

v16.2.0

Compare Source


v16.1.0

Compare Source

This release is the result of a large bug hunt. Many of the fixes make Got match its documented behavior, so you may notice some of them:

  • Invalid options now throw: an empty method, a negative or fractional maxRedirects or retry.limit, a prefixUrl with a query string or fragment, and a handlers entry that is not a function.
  • A stream with a body, json, or form option now rejects writes, as documented.
  • The promise response event now only fires for the final response, not for every retry attempt.
  • got.extend({body}) (and json, form) no longer sends the payload with every request of the instance. Payloads are never merged with defaults.
  • instance.extend() now inherits the parent's mutableDefaults, like got.extend(instance).
  • A HEAD request is no longer changed to GET on a 301, 302, or 303 redirect.
  • response.body no longer keeps a leading UTF-8 byte order mark, and JSON with a byte order mark now parses.

Improvements

  • Accept number values in headers 6fffc9e
  • Export the Timings, DnsCacheLookup, and DnsCacheOptions types d012d1d eccaaca
  • Retry FormData bodies by re-serializing them instead of failing 90c6ec1
  • Support the x-gzip content coding and stacked content codings 5550a79

Fixes


v16.0.0

Compare Source

Breaking changes

  • Rewrite HTTP/2 support and drop the http2-wrapper dependency (#​2464) 1e157c4
    • Got now has a built-in HTTP/2 client: ALPN negotiation, a pooled session cache with multiplexing, GOAWAY retirement, request and response trailers, informational (1xx) responses, abort signals, response caching, IPv6 authorities, and h2c through h2session.
    • agent.http2 is no longer an agent slot. It is only an opt-out flag now: pass false to skip session pooling. Passing an agent instance throws.
    • Response headers no longer contain HTTP/2 pseudo-headers. Use response.statusCode instead of response.headers[':status'].
    • A custom agent.https combined with http2: true makes Got use the native HTTP/1.1 path, because the built-in session pool does not support custom HTTPS agents.
    • HTTP/2 proxy support is gone. It came from http2-wrapper. It was very buggy anyway.
    • If options.request returns a request or response, it controls the transport and the HTTP/2 client is bypassed. Return undefined to fall back to Got's own transport.
  • Rewrite DNS cache and drop the cacheable-lookup dependency (#​2463) bfc400b
    • dnsCache: true now uses Got's own cache. The option accepts any object with a lookup function and an optional clear(hostname?) function, so an existing CacheableLookup instance still works if you keep the dependency yourself.
    • The built-in cache resolves A and AAAA records separately, so it cannot preserve OS-specific verbatim address ordering from dns.lookup().
  • A beforeRequest hook, an afterResponse retry, or a pagination step that moves the request to a different origin now strips credentials and drops the body (#​2465) dd3b295
    • authorization, cookie, cookie2, host, and proxy-authorization are removed, URL credentials are dropped, and an unchanged body is cleared. Set the headers or body explicitly inside the hook if you want them to cross the origin boundary.
    • This applies whether the origin changes through url or through prefixUrl.
  • copyPipedHeaders no longer copies credentials 1d233ba
    • authorization, cookie, cookie2, set-cookie, and set-cookie2 are now omitted along with host, the hop-by-hop headers, and anything nominated by Connection / Proxy-Connection. Pass credentials explicitly in headers when the upstream is trusted.
  • Remove the deprecated searchParameters, followRedirects, and auth option stubs 1d233ba
    • They only existed to throw a guidance message. Passing them now throws Unexpected option: ….
  • Remove the OptionsOfUnknownResponseBody type 1d233ba
    • It was a pure alias for StrictOptions.

Improvements

  • Add support for the QUERY HTTP method (#​2466) e3924aa
    • Adds got.query() and got.stream.query(). QUERY is safe and idempotent, so it is retried by default and keeps a replayable body across 301 and 302 redirects as well as 307 and 308. It is not stored by the built-in cache, because correct QUERY caching needs cache keys that include the request content.
  • allowGetBody now also works over HTTP/2 1e157c4
  • timeout.socket now applies during HTTP/2 TLS negotiation and session setup c6bbb8a
    • It was previously folded into the connection setup timeout and reported as a request timeout. It now produces a real socket timeout and no longer counts DNS lookup time.
  • Two fewer dependencies: cacheable-lookup and http2-wrapper bfc400b 1e157c4

Fixes

  • Retry on connection errors reported by request.end() instead of failing the request (#​2470) 67919b2
  • Retry immediately when the server answers with Retry-After: 0 instead of falling back to the backoff delay (#​2471) d35ce87
  • Preserve the response body when a cookie jar write throws c6bbb8a
    • error.response.body is now complete, decompressed, and decoded with the configured encoding, and a decoding failure no longer masks the original error.
  • Wait for async cookie jar writes on terminal redirect responses, for example with followRedirect: false c6bbb8a
  • Only buffer the response body for cookie handling when the response actually sends set-cookie c6bbb8a
  • Fix got.stream finalizing the response before the response event and before piped server response headers are set c6bbb8a
  • Fix strictContentLength counting bytes from responses that were not actually decompressed c6bbb8a
  • Freeze hooks.beforeCache along with the other hook arrays on non-mutable defaults 1d233ba
  • Keep URL credentials when prefixUrl is changed to a same-origin value, and treat credentials in prefixUrl as explicit dd3b295

Migration guide

HTTP/2

Remove http2-wrapper from your code. Got's HTTP/2 client is built in.

Before:

import http2wrapper from 'http2-wrapper';

const {headers} = await got(url, {
	http2: true,
	request: http2wrapper.auto,
	agent: {
		http2: new http2wrapper.Agent()
	}
});

console.log(headers[':status']);

After:

const {statusCode} = await got(url, {http2: true});

console.log(statusCode);

To opt out of HTTP/2 session pooling for a request, set agent.http2 to false.

If you need an HTTP/2 proxy, keep using http2-wrapper through the request option. Returning a request from request bypasses Got's HTTP/2 client.

h2c

The h2session hook example no longer needs request or http2.

Before:

import http2 from 'http2-wrapper';

got.extend({
	hooks: {
		beforeRequest: [
			options => {
				options.h2session = getSession(options.url);
				options.http2 = true;
				options.request = http2.request;
			}
		]
	}
});

After:

got.extend({
	hooks: {
		beforeRequest: [
			options => {
				options.h2session = getSession(options.url);
			}
		]
	}
});
dnsCache

dnsCache: true keeps working and now uses Got's built-in cache. If you depend on cacheable-lookup specific options, install it yourself and pass the instance:

import CacheableLookup from 'cacheable-lookup';

const dnsCache = new CacheableLookup({maxTtl: 60});

await got(url, {dnsCache});
Cross-origin hooks

If a beforeRequest hook, an afterResponse retry, or a pagination step sends the request to a different origin, set the headers and body you want to keep explicitly:

got.extend({
	hooks: {
		beforeRequest: [
			options => {
				options.url = new URL('https://other.example.com/path');
				options.headers.authorization = 'Bearer …';
			}
		]
	}
});
copyPipedHeaders

Credentials are no longer forwarded from a piped request. Pass them explicitly when the upstream is trusted:

got.stream(url, {
	copyPipedHeaders: true,
	headers: {
		authorization: request.headers.authorization
	}
});

v15.1.0

Compare Source


v15.0.7

Compare Source

  • Fix: Preserve request body on cross-origin 307 and 308 redirects (#​2460) aee9249

v15.0.6

Compare Source

  • Fix searchParams setter dropping the value when a URL is set (#​2454) 5772bf2

v15.0.5

Compare Source

  • Fix: Handle abort signals added by handlers 74e3167

v15.0.4

Compare Source

  • Fix aborting during download progress 11a2202

v15.0.3

Compare Source

  • Fix false ReadError on responses without Content-Length 071ea07

v15.0.2

Compare Source

  • Fix stream cookie jar completion race b170125

v15.0.1

Compare Source


v15.0.0

Compare Source

Breaking changes

  • Require Node.js 22 b933476
  • Remove promise cancel API a06ac6c
  • Remove isStream option c241c6c
    • Use got.stream() directly.
  • Use native FormData global 670b228
  • responseType: 'buffer' returns Uint8Array instead of Buffer 309e36d
    • response.rawBody and promise.buffer() now return a Uint8Array. Buffer is a subclass of Uint8Array, so most code will continue to work, but strict type checks will need updating.
  • strictContentLength defaults to true 08e9dff
    • Got now throws a ContentLengthMismatchError by default if Content-Length doesn't match the actual body size. Set {strictContentLength: false} to restore the old behavior.
  • retry.enforceRetryRules defaults to true 9bc8dfb
    • Custom calculateDelay functions are now only called when a retry is actually allowed by limit, methods, statusCodes, and errorCodes. If your calculateDelay was previously used to override retry eligibility unconditionally, set {retry: {enforceRetryRules: false}}.
  • Piped header copying is now opt-in 8e392f3
    • Got no longer automatically copies headers from a piped stream. Set {copyPipedHeaders: true} to re-enable. Hop-by-hop headers are never copied even when enabled (RFC 9110 §7.6.1).
  • url removed from public options objects 87de8d6
    • The url property is no longer present on the options object passed to hooks. Use response.url or request.requestUrl instead.
  • 300 and 304 responses are no longer auto-followed 5fccaab
    • Per RFC 9110, 304 is a conditional-GET hint, not a redirect, and 300 is only a SHOULD for user agents. Got now returns these responses as-is. Handle them manually if needed.
  • Removed the undocumented named export for Got.
    • Got has always been a default export. The named export was there only for buggy build tools during the ESM migration times.

Improvements

  • Stream decode large text/json bodies incrementally for lower peak memory usage c9a95b1
  • uploadProgress now emits granular per-chunk events for json and form request bodies 13c889d

Migration guide

Replace promise.cancel() with AbortController

Before:

const promise = got(url);
promise.cancel();

After:

const controller = new AbortController();
const promise = got(url, {signal: controller.signal});
controller.abort();
Replace isStream: true with got.stream()

Before:

got(url, {isStream: true});

After:

got.stream(url);
Replace form-data / form-data-encoder with native FormData

Before:

import {FormData} from 'formdata-node';
// or: import {FormData} from 'formdata-polyfill/esm.min.js';

const form = new FormData();
form.set('name', 'value');
await got.post(url, {body: form});

After:

const form = new FormData();
form.set('name', 'value');
await got.post(url, {body: form});
Update Buffer usage to Uint8Array

response.rawBody and promise.buffer() now return Uint8Array instead of Buffer.

Before:

const data = await got(url).buffer();
const copy = Buffer.from(data);

After:

const data = await got(url).buffer();
const copy = new Uint8Array(data);

If you need Buffer-specific APIs, wrap with Buffer.from(data.buffer, data.byteOffset, data.byteLength).

strictContentLength is now on by default

If you send requests where the Content-Length header might not match the actual body size, opt out:

got.extend({strictContentLength: false});
retry.enforceRetryRules is now on by default

If your calculateDelay function was overriding retry eligibility (e.g. retrying on methods or status codes outside the defaults), opt out:

got.extend({
	retry: {
		enforceRetryRules: false,
		calculateDelay: ({computedValue}) => {
			// computedValue is 0 when retry is not allowed
			if (computedValue === 0) {
				return 0;
			}

			return computedValue;
		},
	},
});
Piped header copying is now opt-in

If you pipe streams into Got and rely on automatic header forwarding (e.g. Content-Type), re-enable it:

got.extend({copyPipedHeaders: true});
300 and 304 responses are no longer followed

If your code depended on Got auto-following 300 Multi-Choice or handling 304 Not Modified as a redirect, you now need to handle them yourself in an afterResponse hook or check response.statusCode manually.


v14.6.6

Compare Source

  • Fix stream auto-end for empty PATCH/DELETE/OPTIONS 4d5168c
    • The bug was introduced in b65b0e1, where it incorrectly auto-closed streams for empty PATCH/DELETE/OPTIONS when using streams. This broke the documented use case of piping data to a got stream for these methods.
    • Docs:

      got.stream does not auto-end for OPTIONS, DELETE, or PATCH so you can pipe or write a body without getting write after end. Call stream.end() when you are not piping a body.


v14.6.5

Compare Source

  • Fix TypeScript type inference for got.extend() with responseType option f7ab6e9

v14.6.4

Compare Source

  • Fix dnsLookup option type to accept Node.js dns.lookup 47c3155

v14.6.3

Compare Source


v14.6.2

Compare Source

  • Fix path segments containing colons being misidentified as absolute URLs 0a16a9c

v14.6.1

Compare Source

  • Fix the TS code not being built in 14.6.0.

v14.6.0

Compare Source

Improvements
Fixes
  • Fix HTTP/2 timings NaN issue 398c11a
  • Fix shortcut methods ignoring handler errors f004564
  • Fix body reassignment in beforeRetry hooks bf84d36
  • Fix beforeError hook not being called for ERR_UNSUPPORTED_PROTOCOL error fb86418
  • FIx preserving prefixUrl in hooks 9725fbd
  • Fix race condition causing retry after promise settles 1e49781
  • Fix stream validation errors causing unhandled rejections 2527bf6
  • Fix incorrect content-length when piping decompressed responses 30b3b79
  • Fix EPIPE errors bypassing retry logic in Promise API 6ae3e7f
  • Fix silent hang when returning cached response with FormData body from beforeRequest hook e09a9bd
  • Fix hook type definitions to reflect normalized runtime state 6a544a3
  • Fix afterResponse hook validation to allow null body values 60a4419
  • Fix DNS timing being non-zero when connecting to IP addresses 3d66aec
  • Fix timings.end being undefined when stream is destroyed before completion 4e75679
  • Fix properly treating different UNIX socket paths as different origins e5659d4
Meta

I managed to get it almost down to zero issues! 🎉


v14.5.0

Compare Source

  • Add retry.enforceRetryRules option to fix statusCodes/limit bypassing 7c0aee6
  • Add support for serverName HTTPS option cdaab63
  • Add preserveHooks option for retryWithMergedOptions 1abeba4
  • Support Iterable and AsyncIterable as request body b65b0e1
  • Fix hang on revalidated cached responses 2ab94fd
  • Fix handling of FormData getLength errors a2812de
  • Fix downloadProgress firing for redirect responses 9ec6ff0
  • Fix TypeScript type definition for retry event's createRetryStream parameter e899c07
  • Fix validation to accept false as agent value 6961284
  • Fix HTTP/2 memory leak from timeout listeners with connection reuse d1d4ed2
  • Fix QuickLRU v7+ compatibility 23d0b6b
  • Fix it not using HTTP/2 connection reuse by default 724d592
  • Fix hang with stream requests without body for methods like OPTIONS dc4f1e3

v14.4.9

Compare Source

  • Fix hang with responses containing content-encoding headers but no body cc434bc

v14.4.8

Compare Source

  • Fix infinite loop when retrying with request.options in afterResponse hook dad6a91

v14.4.7

Compare Source


v14.4.6

Compare Source

v14.4.5

Compare Source

v14.4.4

Compare Source

v14.4.3

Compare Source

v14.4.2

Compare Source

v14.4.1

Compare Source

v14.4.0

Compare Source

v14.3.0

Compare Source

v14.2.1

Compare Source

v14.2.0

Compare Source

  • Add cause property with the original error to RequestError (#​2327) 4cbd01d

v14.1.0

Compare Source

v14.0.0

Compare Source

Breaking
  • Require Node.js 20 (#​2313) a004263
    • Why not target the oldest active Node.js LTS, which is Node.js 18? I usually strictly follow this convention in my packages. However, this package is the exception because the HTTP part of Node.js is consistently buggy, and I don't have time to work around issues in older Node.js releases. I you need to still support Node.js 18, I suggest staying on Got v13, which is quite stable. Node.js 18 will be out of active LTS in 5 months.
Improvements

v13.0.0

Compare Source

As a reminder, Got continues to require ESM. For TypeScript users, this includes having "module": "node16", "moduleResolution": "node16" in your tsconfig.

Breaking
Improvements

v12.6.1

Compare Source

v12.6.0

Compare Source

v12.5.3

Compare Source

v12.5.2

Compare Source

v12.5.1

Compare Source

  • Fix compatibility with TypeScript and ESM 3b3ea67
  • Fix request body not being properly cached (#​2150) 3e9d3af

v12.5.0

Compare Source

v12.4.1

Compare Source

Fixes
  • Fix options.context being not extensible b671480
  • Don't emit uploadProgress after promise cancelation 693de21

v12.4.0

Compare Source

Improvements
Fixes
  • Don't call beforeError hooks with HTTPError if the throwHttpErrors option is false (#​2104) 3927348

v12.3.1

Compare Source

v12.3.0

Compare Source

v12.2.0

Compare Source

v12.1.0

Compare Source

Improvements
Fixes

v12.0.4

Compare Source

  • Remove stream lock - unreliable since Node 17.3.0 bb8eca9

v12.0.3

Compare Source

v12.0.2

Compare Source

v12.0.1

Compare Source

v12.0.0

Compare Source

Introducing Got v12.0.0 🎉

Long time no see! The latest Got version (v11.8.2) was released just in February ❄️
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.

  • Please don't open issues about [ERR_REQUIRE_ESM] and Must use import to load ES Module errors. This is a problem with your setup, not Got.
  • Please don't open issues about using Got with Jest. Jest does not fully support ESM.
  • Pretty much any problem with loading this package is a problem with your bundler, test framework, etc, not Got.
  • If you use TypeScript, you will want to stay on Got v11 until TypeScript 4.6 is out. Why.
  • If you use a bundler, make sure it supports ESM and that you have correctly configured it for ESM.
  • The Got issue tracker is not a support channel for your favorite build/bundler tool.
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!

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: false
+    agent: {
+        http: false,
+        https: false,
+        http2: false
+    }
})
  • When passing a url option when paginating, it now needs to be an absolute URL - the prefixUrl option is always reset from now on. The same when retrying in an afterResponse hook.
- return {url: '/location'};
+ return {url: new URL('/location', response.request.options.url)};

There was confusion around the prefixUrl option. It was counterintuitive if used with the Pagination API. For example, it worked fine if the server replied with a relative URL, but if it was an absolute URL then the prefixUrl would end up duplicated. In order to fix this, Got now requires an absolute URL - no prefixUrl will be applied.

  • got.extend(…) will throw when passing some options that don't accept undefined - undefined no longer retains the old value, as setting undefined explicitly may reset the option
Documentation

We have redesigned the documentation so it's easier to navigate and find exactly what you are looking for. We hope you like it ❤️

v11.8.6

Compare Source

  • Destroy request object after successful response

Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate CLI.

This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [got](https://github.com/sindresorhus/got) | [`11.8.5` → `16.2.0`](https://renovatebot.com/diffs/npm/got/11.8.5/16.2.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/got/16.2.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/got/11.8.5/16.2.0?slim=true) | --- ### Release Notes <details> <summary>sindresorhus/got (got)</summary> ### [`v16.2.0`](https://github.com/sindresorhus/got/releases/tag/v16.2.0) [Compare Source](https://github.com/sindresorhus/got/compare/v16.1.0...v16.2.0) - Add Standard Schema support to `.json()` ([#&#8203;2477](https://github.com/sindresorhus/got/issues/2477)) [`d6fb3bd`](https://github.com/sindresorhus/got/commit/d6fb3bda) *** ### [`v16.1.0`](https://github.com/sindresorhus/got/releases/tag/v16.1.0) [Compare Source](https://github.com/sindresorhus/got/compare/v16.0.0...v16.1.0) This release is the result of a large bug hunt. Many of the fixes make Got match its documented behavior, so you may notice some of them: - Invalid options now throw: an empty `method`, a negative or fractional `maxRedirects` or `retry.limit`, a `prefixUrl` with a query string or fragment, and a `handlers` entry that is not a function. - A stream with a `body`, `json`, or `form` option now rejects writes, as documented. - The promise `response` event now only fires for the final response, not for every retry attempt. - `got.extend({body})` (and `json`, `form`) no longer sends the payload with every request of the instance. Payloads are never merged with defaults. - `instance.extend()` now inherits the parent's `mutableDefaults`, like `got.extend(instance)`. - A `HEAD` request is no longer changed to `GET` on a `301`, `302`, or `303` redirect. - `response.body` no longer keeps a leading UTF-8 byte order mark, and JSON with a byte order mark now parses. #### Improvements - Accept number values in `headers` [`6fffc9e`](https://github.com/sindresorhus/got/commit/6fffc9e) - Export the `Timings`, `DnsCacheLookup`, and `DnsCacheOptions` types [`d012d1d`](https://github.com/sindresorhus/got/commit/d012d1d) [`eccaaca`](https://github.com/sindresorhus/got/commit/eccaaca) - Retry `FormData` bodies by re-serializing them instead of failing [`90c6ec1`](https://github.com/sindresorhus/got/commit/90c6ec1) - Support the `x-gzip` content coding and stacked content codings [`5550a79`](https://github.com/sindresorhus/got/commit/5550a79) #### Fixes - Fix many HTTP/2 edge cases, including requests that could hang forever when the response or request was destroyed [`d3c549c`](https://github.com/sindresorhus/got/commit/d3c549c) [`78bf394`](https://github.com/sindresorhus/got/commit/78bf394) [`6bbc7f4`](https://github.com/sindresorhus/got/commit/6bbc7f4) [`602b179`](https://github.com/sindresorhus/got/commit/602b179) [`687b5c8`](https://github.com/sindresorhus/got/commit/687b5c8) [`4ea02b8`](https://github.com/sindresorhus/got/commit/4ea02b8) [`b6522f3`](https://github.com/sindresorhus/got/commit/b6522f3) [`9348ad6`](https://github.com/sindresorhus/got/commit/9348ad6) [`c686386`](https://github.com/sindresorhus/got/commit/c686386) [`3bbc37b`](https://github.com/sindresorhus/got/commit/3bbc37b) [`91dc486`](https://github.com/sindresorhus/got/commit/91dc486) [`11621cd`](https://github.com/sindresorhus/got/commit/11621cd) - Fix `timeout.request` restarting on each redirect, and several timeout phase edge cases [`9cd2ee6`](https://github.com/sindresorhus/got/commit/9cd2ee6) [`df33cdb`](https://github.com/sindresorhus/got/commit/df33cdb) [`4e4c583`](https://github.com/sindresorhus/got/commit/4e4c583) [`795234f`](https://github.com/sindresorhus/got/commit/795234f) [`0f1263d`](https://github.com/sindresorhus/got/commit/0f1263d) - Fix redirects: keep the URL fragment, evaluate `followRedirect` once per response, and keep `Content-Length` correct when a hook replaces the body [`1febf3c`](https://github.com/sindresorhus/got/commit/1febf3c) [`a2b3d90`](https://github.com/sindresorhus/got/commit/a2b3d90) [`1d64f7c`](https://github.com/sindresorhus/got/commit/1d64f7c) [`60b48af`](https://github.com/sindresorhus/got/commit/60b48af) - Fix `Infinity` timeouts firing at once or throwing [`724ebc2`](https://github.com/sindresorhus/got/commit/724ebc2) - Fix retry delay edge cases, including invalid `Retry-After` values and `calculateDelay` for `afterResponse` retries [`fe58b8c`](https://github.com/sindresorhus/got/commit/fe58b8c) [`0193605`](https://github.com/sindresorhus/got/commit/0193605) - Fix retries with replaced or non-replayable bodies [`ae5521f`](https://github.com/sindresorhus/got/commit/ae5521f) [`7c1cda3`](https://github.com/sindresorhus/got/commit/7c1cda3) [`8bbc79f`](https://github.com/sindresorhus/got/commit/8bbc79f) [`1a56d36`](https://github.com/sindresorhus/got/commit/1a56d36) [`d012d1d`](https://github.com/sindresorhus/got/commit/d012d1d) - Fix the default `paginate` on real-world `Link` headers, and several pagination option and limit edge cases [`bd2dee0`](https://github.com/sindresorhus/got/commit/bd2dee0) [`1e61807`](https://github.com/sindresorhus/got/commit/1e61807) [`602b179`](https://github.com/sindresorhus/got/commit/602b179) [`f98d0e1`](https://github.com/sindresorhus/got/commit/f98d0e1) [`c8419e4`](https://github.com/sindresorhus/got/commit/c8419e4) [`526a988`](https://github.com/sindresorhus/got/commit/526a988) [`557e61f`](https://github.com/sindresorhus/got/commit/557e61f) [`4712e5b`](https://github.com/sindresorhus/got/commit/4712e5b) [`a4a50ad`](https://github.com/sindresorhus/got/commit/a4a50ad) [`b65e533`](https://github.com/sindresorhus/got/commit/b65e533) - Fix `afterResponse`, `beforeRequest`, and `beforeCache` hook edge cases [`45c201c`](https://github.com/sindresorhus/got/commit/45c201c) [`c1cf0f8`](https://github.com/sindresorhus/got/commit/c1cf0f8) [`850e49b`](https://github.com/sindresorhus/got/commit/850e49b) [`a4a50ad`](https://github.com/sindresorhus/got/commit/a4a50ad) [`863cf30`](https://github.com/sindresorhus/got/commit/863cf30) [`494279b`](https://github.com/sindresorhus/got/commit/494279b) - Fix response body decoding and parsing edge cases [`c36ad51`](https://github.com/sindresorhus/got/commit/c36ad51) [`c409a84`](https://github.com/sindresorhus/got/commit/c409a84) [`3c6eaf1`](https://github.com/sindresorhus/got/commit/3c6eaf1) [`f658d3e`](https://github.com/sindresorhus/got/commit/f658d3e) [`dbd83df`](https://github.com/sindresorhus/got/commit/dbd83df) - Fix stream edge cases: respect backpressure, stop forwarding after unpipe, and do not copy hop-by-hop headers to a piped `ServerResponse` [`348e114`](https://github.com/sindresorhus/got/commit/348e114) [`dc929bd`](https://github.com/sindresorhus/got/commit/dc929bd) [`dc56e4b`](https://github.com/sindresorhus/got/commit/dc56e4b) [`c930cd9`](https://github.com/sindresorhus/got/commit/c930cd9) [`a9a754f`](https://github.com/sindresorhus/got/commit/a9a754f) - Fix uploads: `DataView` byte ranges, upload error classification, progress `total` for `Content-Length: 0`, and cancelling Web `ReadableStream` bodies [`2a66686`](https://github.com/sindresorhus/got/commit/2a66686) [`d1cb051`](https://github.com/sindresorhus/got/commit/d1cb051) [`0238069`](https://github.com/sindresorhus/got/commit/0238069) [`b57120c`](https://github.com/sindresorhus/got/commit/b57120c) [`200bc85`](https://github.com/sindresorhus/got/commit/200bc85) - Fix option normalization, cloning, and immutable defaults [`8f44d81`](https://github.com/sindresorhus/got/commit/8f44d81) [`687eb7d`](https://github.com/sindresorhus/got/commit/687eb7d) [`30023f7`](https://github.com/sindresorhus/got/commit/30023f7) [`5548b00`](https://github.com/sindresorhus/got/commit/5548b00) [`bec5da6`](https://github.com/sindresorhus/got/commit/bec5da6) [`bcc0b01`](https://github.com/sindresorhus/got/commit/bcc0b01) [`9348ad6`](https://github.com/sindresorhus/got/commit/9348ad6) [`a9a754f`](https://github.com/sindresorhus/got/commit/a9a754f) [`7b13369`](https://github.com/sindresorhus/got/commit/7b13369) [`3bd0486`](https://github.com/sindresorhus/got/commit/3bd0486) [`d272656`](https://github.com/sindresorhus/got/commit/d272656) [`0e537c7`](https://github.com/sindresorhus/got/commit/0e537c7) [`60b62a0`](https://github.com/sindresorhus/got/commit/60b62a0) [`129d88d`](https://github.com/sindresorhus/got/commit/129d88d) - Fix error stacks reporting `RequestError` instead of the real error class, and other error cause edge cases [`c8419e4`](https://github.com/sindresorhus/got/commit/c8419e4) [`9d61a37`](https://github.com/sindresorhus/got/commit/9d61a37) [`5ccac58`](https://github.com/sindresorhus/got/commit/5ccac58) [`71f4e0e`](https://github.com/sindresorhus/got/commit/71f4e0e) - Fix custom DNS cache lookups and DNS records without a valid TTL [`b3dc5c6`](https://github.com/sindresorhus/got/commit/b3dc5c6) [`4ea02b8`](https://github.com/sindresorhus/got/commit/4ea02b8) [`d012d1d`](https://github.com/sindresorhus/got/commit/d012d1d) - Fix cookie edge cases with retries, redirects, and async cookie jars [`784bbd2`](https://github.com/sindresorhus/got/commit/784bbd2) [`d5cd5e4`](https://github.com/sindresorhus/got/commit/d5cd5e4) - Fix diagnostics channel coverage across retries and terminal errors [`cfce7b6`](https://github.com/sindresorhus/got/commit/cfce7b6) - Fix TypeScript types to match the runtime values [`7c833b8`](https://github.com/sindresorhus/got/commit/7c833b8) [`c59692b`](https://github.com/sindresorhus/got/commit/c59692b) [`88eeb13`](https://github.com/sindresorhus/got/commit/88eeb13) [`0c17a8b`](https://github.com/sindresorhus/got/commit/0c17a8b) [`c788ac9`](https://github.com/sindresorhus/got/commit/c788ac9) [`a4176b6`](https://github.com/sindresorhus/got/commit/a4176b6) *** ### [`v16.0.0`](https://github.com/sindresorhus/got/releases/tag/v16.0.0) [Compare Source](https://github.com/sindresorhus/got/compare/v15.1.0...v16.0.0) #### Breaking changes - Rewrite HTTP/2 support and drop the `http2-wrapper` dependency ([#&#8203;2464](https://github.com/sindresorhus/got/issues/2464)) [`1e157c4`](https://github.com/sindresorhus/got/commit/1e157c4) - Got now has a built-in HTTP/2 client: ALPN negotiation, a pooled session cache with multiplexing, `GOAWAY` retirement, request and response trailers, informational (1xx) responses, abort signals, response caching, IPv6 authorities, and `h2c` through `h2session`. - `agent.http2` is no longer an agent slot. It is only an opt-out flag now: pass `false` to skip session pooling. Passing an agent instance throws. - Response headers no longer contain HTTP/2 pseudo-headers. Use `response.statusCode` instead of `response.headers[':status']`. - A custom `agent.https` combined with `http2: true` makes Got use the native HTTP/1.1 path, because the built-in session pool does not support custom HTTPS agents. - HTTP/2 proxy support is gone. It came from `http2-wrapper`. It was very buggy anyway. - If `options.request` returns a request or response, it controls the transport and the HTTP/2 client is bypassed. Return `undefined` to fall back to Got's own transport. - Rewrite DNS cache and drop the `cacheable-lookup` dependency ([#&#8203;2463](https://github.com/sindresorhus/got/issues/2463)) [`bfc400b`](https://github.com/sindresorhus/got/commit/bfc400b) - `dnsCache: true` now uses Got's own cache. The option accepts any object with a `lookup` function and an optional `clear(hostname?)` function, so an existing `CacheableLookup` instance still works if you keep the dependency yourself. - The built-in cache resolves A and AAAA records separately, so it cannot preserve OS-specific `verbatim` address ordering from `dns.lookup()`. - A `beforeRequest` hook, an `afterResponse` retry, or a pagination step that moves the request to a different origin now strips credentials and drops the body ([#&#8203;2465](https://github.com/sindresorhus/got/issues/2465)) [`dd3b295`](https://github.com/sindresorhus/got/commit/dd3b295) - `authorization`, `cookie`, `cookie2`, `host`, and `proxy-authorization` are removed, URL credentials are dropped, and an unchanged body is cleared. Set the headers or body explicitly inside the hook if you want them to cross the origin boundary. - This applies whether the origin changes through `url` or through `prefixUrl`. - `copyPipedHeaders` no longer copies credentials [`1d233ba`](https://github.com/sindresorhus/got/commit/1d233ba) - `authorization`, `cookie`, `cookie2`, `set-cookie`, and `set-cookie2` are now omitted along with `host`, the hop-by-hop headers, and anything nominated by `Connection` / `Proxy-Connection`. Pass credentials explicitly in `headers` when the upstream is trusted. - Remove the deprecated `searchParameters`, `followRedirects`, and `auth` option stubs [`1d233ba`](https://github.com/sindresorhus/got/commit/1d233ba) - They only existed to throw a guidance message. Passing them now throws `Unexpected option: …`. - Remove the `OptionsOfUnknownResponseBody` type [`1d233ba`](https://github.com/sindresorhus/got/commit/1d233ba) - It was a pure alias for `StrictOptions`. #### Improvements - Add support for the [`QUERY`](https://www.rfc-editor.org/rfc/rfc10008.html) HTTP method ([#&#8203;2466](https://github.com/sindresorhus/got/issues/2466)) [`e3924aa`](https://github.com/sindresorhus/got/commit/e3924aa) - Adds `got.query()` and `got.stream.query()`. `QUERY` is safe and idempotent, so it is retried by default and keeps a replayable body across `301` and `302` redirects as well as `307` and `308`. It is not stored by the built-in cache, because correct `QUERY` caching needs cache keys that include the request content. - `allowGetBody` now also works over HTTP/2 [`1e157c4`](https://github.com/sindresorhus/got/commit/1e157c4) - `timeout.socket` now applies during HTTP/2 TLS negotiation and session setup [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - It was previously folded into the connection setup timeout and reported as a `request` timeout. It now produces a real `socket` timeout and no longer counts DNS lookup time. - Two fewer dependencies: `cacheable-lookup` and `http2-wrapper` [`bfc400b`](https://github.com/sindresorhus/got/commit/bfc400b) [`1e157c4`](https://github.com/sindresorhus/got/commit/1e157c4) #### Fixes - Retry on connection errors reported by `request.end()` instead of failing the request ([#&#8203;2470](https://github.com/sindresorhus/got/issues/2470)) [`67919b2`](https://github.com/sindresorhus/got/commit/67919b2) - Retry immediately when the server answers with `Retry-After: 0` instead of falling back to the backoff delay ([#&#8203;2471](https://github.com/sindresorhus/got/issues/2471)) [`d35ce87`](https://github.com/sindresorhus/got/commit/d35ce87) - Preserve the response body when a cookie jar write throws [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - `error.response.body` is now complete, decompressed, and decoded with the configured `encoding`, and a decoding failure no longer masks the original error. - Wait for async cookie jar writes on terminal redirect responses, for example with `followRedirect: false` [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - Only buffer the response body for cookie handling when the response actually sends `set-cookie` [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - Fix `got.stream` finalizing the response before the `response` event and before piped server response headers are set [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - Fix `strictContentLength` counting bytes from responses that were not actually decompressed [`c6bbb8a`](https://github.com/sindresorhus/got/commit/c6bbb8a) - Freeze `hooks.beforeCache` along with the other hook arrays on non-mutable defaults [`1d233ba`](https://github.com/sindresorhus/got/commit/1d233ba) - Keep URL credentials when `prefixUrl` is changed to a same-origin value, and treat credentials in `prefixUrl` as explicit [`dd3b295`](https://github.com/sindresorhus/got/commit/dd3b295) #### Migration guide ##### HTTP/2 Remove `http2-wrapper` from your code. Got's HTTP/2 client is built in. **Before:** ```js import http2wrapper from 'http2-wrapper'; const {headers} = await got(url, { http2: true, request: http2wrapper.auto, agent: { http2: new http2wrapper.Agent() } }); console.log(headers[':status']); ``` **After:** ```js const {statusCode} = await got(url, {http2: true}); console.log(statusCode); ``` To opt out of HTTP/2 session pooling for a request, set `agent.http2` to `false`. If you need an HTTP/2 proxy, keep using `http2-wrapper` through the `request` option. Returning a request from `request` bypasses Got's HTTP/2 client. ##### `h2c` The `h2session` hook example no longer needs `request` or `http2`. **Before:** ```js import http2 from 'http2-wrapper'; got.extend({ hooks: { beforeRequest: [ options => { options.h2session = getSession(options.url); options.http2 = true; options.request = http2.request; } ] } }); ``` **After:** ```js got.extend({ hooks: { beforeRequest: [ options => { options.h2session = getSession(options.url); } ] } }); ``` ##### `dnsCache` `dnsCache: true` keeps working and now uses Got's built-in cache. If you depend on `cacheable-lookup` specific options, install it yourself and pass the instance: ```js import CacheableLookup from 'cacheable-lookup'; const dnsCache = new CacheableLookup({maxTtl: 60}); await got(url, {dnsCache}); ``` ##### Cross-origin hooks If a `beforeRequest` hook, an `afterResponse` retry, or a pagination step sends the request to a different origin, set the headers and body you want to keep explicitly: ```js got.extend({ hooks: { beforeRequest: [ options => { options.url = new URL('https://other.example.com/path'); options.headers.authorization = 'Bearer …'; } ] } }); ``` ##### `copyPipedHeaders` Credentials are no longer forwarded from a piped request. Pass them explicitly when the upstream is trusted: ```js got.stream(url, { copyPipedHeaders: true, headers: { authorization: request.headers.authorization } }); ``` *** ### [`v15.1.0`](https://github.com/sindresorhus/got/releases/tag/v15.1.0) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.7...v15.1.0) - Add [`allowAbsoluteUrls`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#allowabsoluteurls) option ([#&#8203;2462](https://github.com/sindresorhus/got/issues/2462)) [`1c88e88`](https://github.com/sindresorhus/got/commit/1c88e88) *** ### [`v15.0.7`](https://github.com/sindresorhus/got/releases/tag/v15.0.7) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.6...v15.0.7) - Fix: Preserve request body on cross-origin 307 and 308 redirects ([#&#8203;2460](https://github.com/sindresorhus/got/issues/2460)) [`aee9249`](https://github.com/sindresorhus/got/commit/aee9249) *** ### [`v15.0.6`](https://github.com/sindresorhus/got/releases/tag/v15.0.6) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.5...v15.0.6) - Fix `searchParams` setter dropping the value when a URL is set ([#&#8203;2454](https://github.com/sindresorhus/got/issues/2454)) [`5772bf2`](https://github.com/sindresorhus/got/commit/5772bf2) *** ### [`v15.0.5`](https://github.com/sindresorhus/got/releases/tag/v15.0.5) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.4...v15.0.5) - Fix: Handle abort signals added by handlers [`74e3167`](https://github.com/sindresorhus/got/commit/74e3167) *** ### [`v15.0.4`](https://github.com/sindresorhus/got/releases/tag/v15.0.4) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.3...v15.0.4) - Fix aborting during download progress [`11a2202`](https://github.com/sindresorhus/got/commit/11a2202) *** ### [`v15.0.3`](https://github.com/sindresorhus/got/releases/tag/v15.0.3) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.2...v15.0.3) - Fix false `ReadError` on responses without `Content-Length` [`071ea07`](https://github.com/sindresorhus/got/commit/071ea07) *** ### [`v15.0.2`](https://github.com/sindresorhus/got/releases/tag/v15.0.2) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.1...v15.0.2) - Fix stream cookie jar completion race [`b170125`](https://github.com/sindresorhus/got/commit/b170125) *** ### [`v15.0.1`](https://github.com/sindresorhus/got/releases/tag/v15.0.1) [Compare Source](https://github.com/sindresorhus/got/compare/v15.0.0...v15.0.1) - Fix init types [`20633bc`](https://github.com/sindresorhus/got/commit/20633bc) *** ### [`v15.0.0`](https://github.com/sindresorhus/got/releases/tag/v15.0.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.6...v15.0.0) #### Breaking changes - Require Node.js 22 [`b933476`](https://github.com/sindresorhus/got/commit/b933476) - Remove promise cancel API [`a06ac6c`](https://github.com/sindresorhus/got/commit/a06ac6c) - `promise.cancel()` is gone. Use the [`signal` option](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#signal) with [`AbortController`](https://developer.mozilla.org/docs/Web/API/AbortController) instead. - Remove `isStream` option [`c241c6c`](https://github.com/sindresorhus/got/commit/c241c6c) - Use `got.stream()` directly. - Use native `FormData` global [`670b228`](https://github.com/sindresorhus/got/commit/670b228) - Use the [Web API `FormData`](https://developer.mozilla.org/docs/Web/API/FormData) global directly (available in Node.js 18+). - `responseType: 'buffer'` returns `Uint8Array` instead of `Buffer` [`309e36d`](https://github.com/sindresorhus/got/commit/309e36d) - `response.rawBody` and `promise.buffer()` now return a `Uint8Array`. `Buffer` is a subclass of `Uint8Array`, so most code will continue to work, but strict type checks will need updating. - `strictContentLength` defaults to `true` [`08e9dff`](https://github.com/sindresorhus/got/commit/08e9dff) - Got now throws a `ContentLengthMismatchError` by default if `Content-Length` doesn't match the actual body size. Set `{strictContentLength: false}` to restore the old behavior. - `retry.enforceRetryRules` defaults to `true` [`9bc8dfb`](https://github.com/sindresorhus/got/commit/9bc8dfb) - Custom `calculateDelay` functions are now only called when a retry is actually allowed by `limit`, `methods`, `statusCodes`, and `errorCodes`. If your `calculateDelay` was previously used to override retry eligibility unconditionally, set `{retry: {enforceRetryRules: false}}`. - Piped header copying is now opt-in [`8e392f3`](https://github.com/sindresorhus/got/commit/8e392f3) - Got no longer automatically copies headers from a piped stream. Set `{copyPipedHeaders: true}` to re-enable. Hop-by-hop headers are never copied even when enabled (RFC 9110 §7.6.1). - `url` removed from public options objects [`87de8d6`](https://github.com/sindresorhus/got/commit/87de8d6) - The `url` property is no longer present on the options object passed to hooks. Use `response.url` or `request.requestUrl` instead. - 300 and 304 responses are no longer auto-followed [`5fccaab`](https://github.com/sindresorhus/got/commit/5fccaab) - Per RFC 9110, 304 is a conditional-GET hint, not a redirect, and 300 is only a SHOULD for user agents. Got now returns these responses as-is. Handle them manually if needed. - Removed the undocumented named export for Got. - Got has always been a default export. The named export was there only for buggy build tools during the ESM migration times. #### Improvements - Stream decode large `text`/`json` bodies incrementally for lower peak memory usage [`c9a95b1`](https://github.com/sindresorhus/got/commit/c9a95b1) - `uploadProgress` now emits granular per-chunk events for `json` and `form` request bodies [`13c889d`](https://github.com/sindresorhus/got/commit/13c889d) *** #### Migration guide ##### Replace `promise.cancel()` with `AbortController` **Before:** ```js const promise = got(url); promise.cancel(); ``` **After:** ```js const controller = new AbortController(); const promise = got(url, {signal: controller.signal}); controller.abort(); ``` ##### Replace `isStream: true` with `got.stream()` **Before:** ```js got(url, {isStream: true}); ``` **After:** ```js got.stream(url); ``` ##### Replace `form-data` / `form-data-encoder` with native `FormData` **Before:** ```js import {FormData} from 'formdata-node'; // or: import {FormData} from 'formdata-polyfill/esm.min.js'; const form = new FormData(); form.set('name', 'value'); await got.post(url, {body: form}); ``` **After:** ```js const form = new FormData(); form.set('name', 'value'); await got.post(url, {body: form}); ``` ##### Update `Buffer` usage to `Uint8Array` `response.rawBody` and `promise.buffer()` now return `Uint8Array` instead of `Buffer`. **Before:** ```js const data = await got(url).buffer(); const copy = Buffer.from(data); ``` **After:** ```js const data = await got(url).buffer(); const copy = new Uint8Array(data); ``` If you need `Buffer`-specific APIs, wrap with `Buffer.from(data.buffer, data.byteOffset, data.byteLength)`. ##### `strictContentLength` is now on by default If you send requests where the `Content-Length` header might not match the actual body size, opt out: ```js got.extend({strictContentLength: false}); ``` ##### `retry.enforceRetryRules` is now on by default If your `calculateDelay` function was overriding retry eligibility (e.g. retrying on methods or status codes outside the defaults), opt out: ```js got.extend({ retry: { enforceRetryRules: false, calculateDelay: ({computedValue}) => { // computedValue is 0 when retry is not allowed if (computedValue === 0) { return 0; } return computedValue; }, }, }); ``` ##### Piped header copying is now opt-in If you pipe streams into Got and rely on automatic header forwarding (e.g. `Content-Type`), re-enable it: ```js got.extend({copyPipedHeaders: true}); ``` ##### 300 and 304 responses are no longer followed If your code depended on Got auto-following 300 Multi-Choice or handling 304 Not Modified as a redirect, you now need to handle them yourself in an `afterResponse` hook or check `response.statusCode` manually. *** ### [`v14.6.6`](https://github.com/sindresorhus/got/releases/tag/v14.6.6) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.5...v14.6.6) - Fix stream auto-end for empty PATCH/DELETE/OPTIONS [`4d5168c`](https://github.com/sindresorhus/got/commit/4d5168c) - The bug was introduced in [`b65b0e1`](https://github.com/sindresorhus/got/commit/b65b0e1c300d745eb6956a4fb0bd19f3b177e144), where it incorrectly auto-closed streams for empty PATCH/DELETE/OPTIONS when using streams. This broke the documented use case of piping data *to* a got stream for these methods. - Docs: > `got.stream` does not auto-end for `OPTIONS`, `DELETE`, or `PATCH` so you can pipe or write a body without getting `write after end`. Call `stream.end()` when you are not piping a body. *** ### [`v14.6.5`](https://github.com/sindresorhus/got/releases/tag/v14.6.5) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.4...v14.6.5) - Fix TypeScript type inference for `got.extend()` with `responseType` option [`f7ab6e9`](https://github.com/sindresorhus/got/commit/f7ab6e9) *** ### [`v14.6.4`](https://github.com/sindresorhus/got/releases/tag/v14.6.4) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.3...v14.6.4) - Fix `dnsLookup` option type to accept Node.js `dns.lookup` [`47c3155`](https://github.com/sindresorhus/got/commit/47c3155) *** ### [`v14.6.3`](https://github.com/sindresorhus/got/releases/tag/v14.6.3) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.2...v14.6.3) - Fix socket reuse timing and DNS timing [`fb03d84`](https://github.com/sindresorhus/got/commit/fb03d84) [`61d5e3b`](https://github.com/sindresorhus/got/commit/61d5e3b) *** ### [`v14.6.2`](https://github.com/sindresorhus/got/releases/tag/v14.6.2) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.1...v14.6.2) - Fix path segments containing colons being misidentified as absolute URLs [`0a16a9c`](https://github.com/sindresorhus/got/commit/0a16a9c) *** ### [`v14.6.1`](https://github.com/sindresorhus/got/releases/tag/v14.6.1) [Compare Source](https://github.com/sindresorhus/got/compare/v14.6.0...v14.6.1) - Fix the TS code not being built in 14.6.0. *** ### [`v14.6.0`](https://github.com/sindresorhus/got/releases/tag/v14.6.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.5.0...v14.6.0) ##### Improvements - Add [`beforeCache`](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/9-hooks.md?plain=1#L237) hook [`1c3a041`](https://github.com/sindresorhus/got/commit/1c3a041) - Add `retryCount` to `beforeRequest` hook context [`91cdc48`](https://github.com/sindresorhus/got/commit/91cdc48) - Improve `HTTPError` message to include method and URL [`6dd7574`](https://github.com/sindresorhus/got/commit/6dd7574) - Add support for typed arrays as request body [`ecf5633`](https://github.com/sindresorhus/got/commit/ecf5633) - Add Node.js [diagnostic channel support](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/diagnostics-channel.md) [`3e2a781`](https://github.com/sindresorhus/got/commit/3e2a781) - Allow custom Error classes in `beforeError` hook [`1c71194`](https://github.com/sindresorhus/got/commit/1c71194) - Add zstd (Zstandard) compression support [`449833a`](https://github.com/sindresorhus/got/commit/449833a) - Improve validation error messages by including option names [`f5c54a3`](https://github.com/sindresorhus/got/commit/f5c54a3) - Add [`strictContentLength`](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/2-options.md?plain=1#L854) option [`4206f0e`](https://github.com/sindresorhus/got/commit/4206f0e) - Add support for [`https.secureOptions`](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/5-https.md?plain=1#L136) option [`7ec1714`](https://github.com/sindresorhus/got/commit/7ec1714) - Add [`copyPipedHeaders`](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/2-options.md?plain=1#L526) option to control automatic header copying from piped streams [`d83dadd`](https://github.com/sindresorhus/got/commit/d83dadd) - Add [`stream.isReadonly`](https://github.com/sindresorhus/got/blob/599ae74e9f2a002eade81a0ec1722cf7dc28a9cd/documentation/3-streams.md?plain=1#L172) property to detect read-only streams [`030dfbb`](https://github.com/sindresorhus/got/commit/030dfbb) ##### Fixes - Fix HTTP/2 timings NaN issue [`398c11a`](https://github.com/sindresorhus/got/commit/398c11a) - Fix shortcut methods ignoring handler errors [`f004564`](https://github.com/sindresorhus/got/commit/f004564) - Fix body reassignment in `beforeRetry` hooks [`bf84d36`](https://github.com/sindresorhus/got/commit/bf84d36) - Fix `beforeError` hook not being called for `ERR_UNSUPPORTED_PROTOCOL` error [`fb86418`](https://github.com/sindresorhus/got/commit/fb86418) - FIx preserving `prefixUrl` in hooks [`9725fbd`](https://github.com/sindresorhus/got/commit/9725fbd) - Fix race condition causing retry after promise settles [`1e49781`](https://github.com/sindresorhus/got/commit/1e49781) - Fix stream validation errors causing unhandled rejections [`2527bf6`](https://github.com/sindresorhus/got/commit/2527bf6) - Fix incorrect `content-length` when piping decompressed responses [`30b3b79`](https://github.com/sindresorhus/got/commit/30b3b79) - Fix EPIPE errors bypassing retry logic in Promise API [`6ae3e7f`](https://github.com/sindresorhus/got/commit/6ae3e7f) - Fix silent hang when returning cached response with FormData body from beforeRequest hook [`e09a9bd`](https://github.com/sindresorhus/got/commit/e09a9bd) - Fix hook type definitions to reflect normalized runtime state [`6a544a3`](https://github.com/sindresorhus/got/commit/6a544a3) - Fix `afterResponse` hook validation to allow `null` body values [`60a4419`](https://github.com/sindresorhus/got/commit/60a4419) - Fix DNS timing being non-zero when connecting to IP addresses [`3d66aec`](https://github.com/sindresorhus/got/commit/3d66aec) - Fix `timings.end` being undefined when stream is destroyed before completion [`4e75679`](https://github.com/sindresorhus/got/commit/4e75679) - Fix properly treating different UNIX socket paths as different origins [`e5659d4`](https://github.com/sindresorhus/got/commit/e5659d4) ##### Meta I managed to get it almost down to zero issues! 🎉 *** ### [`v14.5.0`](https://github.com/sindresorhus/got/releases/tag/v14.5.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.9...v14.5.0) - Add `retry.enforceRetryRules` option to fix statusCodes/limit bypassing [`7c0aee6`](https://github.com/sindresorhus/got/commit/7c0aee6) - Add support for `serverName` HTTPS option [`cdaab63`](https://github.com/sindresorhus/got/commit/cdaab63) - Add `preserveHooks` option for `retryWithMergedOptions` [`1abeba4`](https://github.com/sindresorhus/got/commit/1abeba4) - Support `Iterable` and `AsyncIterable` as request body [`b65b0e1`](https://github.com/sindresorhus/got/commit/b65b0e1) - Fix hang on revalidated cached responses [`2ab94fd`](https://github.com/sindresorhus/got/commit/2ab94fd) - Fix handling of FormData getLength errors [`a2812de`](https://github.com/sindresorhus/got/commit/a2812de) - Fix `downloadProgress` firing for redirect responses [`9ec6ff0`](https://github.com/sindresorhus/got/commit/9ec6ff0) - Fix TypeScript type definition for retry event's createRetryStream parameter [`e899c07`](https://github.com/sindresorhus/got/commit/e899c07) - Fix validation to accept `false` as agent value [`6961284`](https://github.com/sindresorhus/got/commit/6961284) - Fix HTTP/2 memory leak from timeout listeners with connection reuse [`d1d4ed2`](https://github.com/sindresorhus/got/commit/d1d4ed2) - Fix QuickLRU v7+ compatibility [`23d0b6b`](https://github.com/sindresorhus/got/commit/23d0b6b) - Fix it not using HTTP/2 connection reuse by default [`724d592`](https://github.com/sindresorhus/got/commit/724d592) - Fix hang with stream requests without body for methods like OPTIONS [`dc4f1e3`](https://github.com/sindresorhus/got/commit/dc4f1e3) *** ### [`v14.4.9`](https://github.com/sindresorhus/got/releases/tag/v14.4.9) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.8...v14.4.9) - Fix hang with responses containing `content-encoding` headers but no body [`cc434bc`](https://github.com/sindresorhus/got/commit/cc434bc) *** ### [`v14.4.8`](https://github.com/sindresorhus/got/releases/tag/v14.4.8) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.7...v14.4.8) - Fix infinite loop when retrying with `request.options` in `afterResponse` hook [`dad6a91`](https://github.com/sindresorhus/got/commit/dad6a91) *** ### [`v14.4.7`](https://github.com/sindresorhus/got/releases/tag/v14.4.7) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.6...v14.4.7) - Fix: Gracefully handle undefined request ([#&#8203;2404](https://github.com/sindresorhus/got/issues/2404)) [`06029e0`](https://github.com/sindresorhus/got/commit/06029e0) *** ### [`v14.4.6`](https://github.com/sindresorhus/got/releases/tag/v14.4.6) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.5...v14.4.6) - Fix timeout error firing even though it's cancelled ([#&#8203;2399](https://github.com/sindresorhus/got/issues/2399)) [`7a92064`](https://github.com/sindresorhus/got/commit/7a92064) ### [`v14.4.5`](https://github.com/sindresorhus/got/releases/tag/v14.4.5) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.4...v14.4.5) - Fix a crash with Got accessing a non-existent request ([#&#8203;2391](https://github.com/sindresorhus/got/issues/2391)) [`c079b93`](https://github.com/sindresorhus/got/commit/c079b93) ### [`v14.4.4`](https://github.com/sindresorhus/got/releases/tag/v14.4.4) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.3...v14.4.4) - Fix support for `AbortSignal#timeout()` ([#&#8203;2388](https://github.com/sindresorhus/got/issues/2388)) [`92b378e`](https://github.com/sindresorhus/got/commit/92b378e) ### [`v14.4.3`](https://github.com/sindresorhus/got/releases/tag/v14.4.3) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.2...v14.4.3) - Fix cache with HTTP2 ([#&#8203;2380](https://github.com/sindresorhus/got/issues/2380)) [`f2f8cb2`](https://github.com/sindresorhus/got/commit/f2f8cb2) ### [`v14.4.2`](https://github.com/sindresorhus/got/releases/tag/v14.4.2) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.1...v14.4.2) - Fix handling of invalid arguments ([#&#8203;2367](https://github.com/sindresorhus/got/issues/2367)) [`f44ef43`](https://github.com/sindresorhus/got/commit/f44ef43) ### [`v14.4.1`](https://github.com/sindresorhus/got/releases/tag/v14.4.1) [Compare Source](https://github.com/sindresorhus/got/compare/v14.4.0...v14.4.1) - Fix missing dependency [`dfc54d9`](https://github.com/sindresorhus/got/commit/dfc54d9) ### [`v14.4.0`](https://github.com/sindresorhus/got/releases/tag/v14.4.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.3.0...v14.4.0) - Improve TypeScript types with generic extend ([#&#8203;2353](https://github.com/sindresorhus/got/issues/2353)) [`15ca4a0`](https://github.com/sindresorhus/got/commit/15ca4a0) ### [`v14.3.0`](https://github.com/sindresorhus/got/releases/tag/v14.3.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.2.1...v14.3.0) - Update dependencies [`dbab6c3`](https://github.com/sindresorhus/got/commit/dbab6c3) ### [`v14.2.1`](https://github.com/sindresorhus/got/releases/tag/v14.2.1) [Compare Source](https://github.com/sindresorhus/got/compare/v14.2.0...v14.2.1) - Fix error handling when UTF-8 decoding fails ([#&#8203;2336](https://github.com/sindresorhus/got/issues/2336)) [`c81a611`](https://github.com/sindresorhus/got/commit/c81a611) ### [`v14.2.0`](https://github.com/sindresorhus/got/releases/tag/v14.2.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.1.0...v14.2.0) - Add `cause` property with the original error to `RequestError` ([#&#8203;2327](https://github.com/sindresorhus/got/issues/2327)) [`4cbd01d`](https://github.com/sindresorhus/got/commit/4cbd01d) ### [`v14.1.0`](https://github.com/sindresorhus/got/releases/tag/v14.1.0) [Compare Source](https://github.com/sindresorhus/got/compare/v14.0.0...v14.1.0) - Allow typing the body of a `RequestError` response ([#&#8203;2325](https://github.com/sindresorhus/got/issues/2325)) [`5e4f6ff`](https://github.com/sindresorhus/got/commit/5e4f6ff) ### [`v14.0.0`](https://github.com/sindresorhus/got/releases/tag/v14.0.0) [Compare Source](https://github.com/sindresorhus/got/compare/v13.0.0...v14.0.0) ##### Breaking - Require Node.js 20 ([#&#8203;2313](https://github.com/sindresorhus/got/issues/2313)) [`a004263`](https://github.com/sindresorhus/got/commit/a004263) - Why not target the oldest active Node.js LTS, which is Node.js 18? I usually strictly follow this convention in my packages. However, this package is the exception because the HTTP part of Node.js is consistently buggy, and I don't have time to work around issues in older Node.js releases. I you need to still support Node.js 18, I suggest staying on Got v13, which is quite stable. Node.js 18 will be out of active LTS in 5 months. ##### Improvements - Make `followRedirect` option accept a function ([#&#8203;2306](https://github.com/sindresorhus/got/issues/2306)) [`7c3f147`](https://github.com/sindresorhus/got/commit/7c3f147) ### [`v13.0.0`](https://github.com/sindresorhus/got/releases/tag/v13.0.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.6.1...v13.0.0) As a reminder, Got continues to require ESM. For TypeScript users, this includes having [`"module": "node16", "moduleResolution": "node16"` in your tsconfig](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm). ##### Breaking - Require Node.js 16 [`52a1063`](https://github.com/sindresorhus/got/commit/52a1063) - Change the [`enableUnixSockets`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#enableunixsockets) option to be `false` by default [`852c312`](https://github.com/sindresorhus/got/commit/852c312) - Most users don't need it. ##### Improvements - Allow specifying `undefined` for options ([#&#8203;2258](https://github.com/sindresorhus/got/issues/2258)) [`1cefe8b`](https://github.com/sindresorhus/got/commit/1cefe8b) ### [`v12.6.1`](https://github.com/sindresorhus/got/releases/tag/v12.6.1) [Compare Source](https://github.com/sindresorhus/got/compare/v12.6.0...v12.6.1) - Fix `get-stream` import statement ([#&#8203;2266](https://github.com/sindresorhus/got/issues/2266)) [`67d5039`](https://github.com/sindresorhus/got/commit/67d5039) ### [`v12.6.0`](https://github.com/sindresorhus/got/releases/tag/v12.6.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.5.3...v12.6.0) - Update dependencies [`88c88fb`](https://github.com/sindresorhus/got/commit/88c88fb) [`979272e`](https://github.com/sindresorhus/got/commit/979272e) - Loosen URL validation strictness ([#&#8203;2200](https://github.com/sindresorhus/got/issues/2200)) [`0ca0b7f`](https://github.com/sindresorhus/got/commit/0ca0b7f) ### [`v12.5.3`](https://github.com/sindresorhus/got/releases/tag/v12.5.3) [Compare Source](https://github.com/sindresorhus/got/compare/v12.5.2...v12.5.3) - Fix abort event listeners not always being cleaned up ([#&#8203;2162](https://github.com/sindresorhus/got/issues/2162)) [`3cc40b5`](https://github.com/sindresorhus/got/commit/3cc40b5) ### [`v12.5.2`](https://github.com/sindresorhus/got/releases/tag/v12.5.2) [Compare Source](https://github.com/sindresorhus/got/compare/v12.5.1...v12.5.2) - Improve TypeScript 4.9 compatibility ([#&#8203;2163](https://github.com/sindresorhus/got/issues/2163)) [`39f83b6`](https://github.com/sindresorhus/got/commit/39f83b6) ### [`v12.5.1`](https://github.com/sindresorhus/got/releases/tag/v12.5.1) [Compare Source](https://github.com/sindresorhus/got/compare/v12.5.0...v12.5.1) - Fix compatibility with TypeScript and ESM [`3b3ea67`](https://github.com/sindresorhus/got/commit/3b3ea67) - Fix request body not being properly cached ([#&#8203;2150](https://github.com/sindresorhus/got/issues/2150)) [`3e9d3af`](https://github.com/sindresorhus/got/commit/3e9d3af) ### [`v12.5.0`](https://github.com/sindresorhus/got/releases/tag/v12.5.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.4.1...v12.5.0) - Disable method rewriting on 307 and 308 status codes ([#&#8203;2145](https://github.com/sindresorhus/got/issues/2145)) [`e049e94`](https://github.com/sindresorhus/got/commit/e049e94) - Upgrade dependencies [`8630815`](https://github.com/sindresorhus/got/commit/8630815) [`f0ac0b3`](https://github.com/sindresorhus/got/commit/f0ac0b3) [`4c3762a`](https://github.com/sindresorhus/got/commit/4c3762a) ### [`v12.4.1`](https://github.com/sindresorhus/got/releases/tag/v12.4.1) [Compare Source](https://github.com/sindresorhus/got/compare/v12.4.0...v12.4.1) ##### Fixes - Fix `options.context` being not extensible [`b671480`](https://github.com/sindresorhus/got/commit/b671480715dbbff908e9a385f5e714570c663cd7) - Don't emit `uploadProgress` after promise cancelation [`693de21`](https://github.com/sindresorhus/got/commit/693de217b030816f574d6e4cb505ee2e77b21c29) ### [`v12.4.0`](https://github.com/sindresorhus/got/releases/tag/v12.4.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.3.1...v12.4.0) ##### Improvements - Support FormData without known length ([#&#8203;2120](https://github.com/sindresorhus/got/issues/2120)) [`850773c`](https://github.com/sindresorhus/got/commit/850773c) ##### Fixes - Don't call `beforeError` hooks with `HTTPError` if the `throwHttpErrors` option is `false` ([#&#8203;2104](https://github.com/sindresorhus/got/issues/2104)) [`3927348`](https://github.com/sindresorhus/got/commit/3927348) ### [`v12.3.1`](https://github.com/sindresorhus/got/releases/tag/v12.3.1) [Compare Source](https://github.com/sindresorhus/got/compare/v12.3.0...v12.3.1) - Don't freeze signal when freezing Options ([#&#8203;2100](https://github.com/sindresorhus/got/issues/2100)) [`43b1467`](https://github.com/sindresorhus/got/commit/43b1467) ### [`v12.3.0`](https://github.com/sindresorhus/got/releases/tag/v12.3.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.2.0...v12.3.0) - Add `.off()` method for events ([#&#8203;2092](https://github.com/sindresorhus/got/issues/2092)) [`88056be`](https://github.com/sindresorhus/got/commit/88056be) ### [`v12.2.0`](https://github.com/sindresorhus/got/releases/tag/v12.2.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.1.0...v12.2.0) - [Support `AbortController`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#signal) ([#&#8203;2020](https://github.com/sindresorhus/got/issues/2020)) [`6a6d2a9`](https://github.com/sindresorhus/got/commit/6a6d2a9) - Add [`enableUnixSockets`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#enableunixsockets) option ([#&#8203;2062](https://github.com/sindresorhus/got/issues/2062)) [`461b3d4`](https://github.com/sindresorhus/got/commit/461b3d4) ### [`v12.1.0`](https://github.com/sindresorhus/got/releases/tag/v12.1.0) [Compare Source](https://github.com/sindresorhus/got/compare/v12.0.4...v12.1.0) ##### Improvements - Add `response.ok` ([#&#8203;2043](https://github.com/sindresorhus/got/issues/2043)) [`22d58fb`](https://github.com/sindresorhus/got/commit/22d58fb) - This is only useful if you have [`{throwHttpErrors: false}`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#throwhttperrors) ##### Fixes - Do not redirect to UNIX sockets ([#&#8203;2047](https://github.com/sindresorhus/got/issues/2047)) [`861ccd9`](https://github.com/sindresorhus/got/commit/861ccd9) - [CVE-2022-33987](https://nvd.nist.gov/vuln/detail/CVE-2022-33987) - [Also back ported to v11](https://github.com/sindresorhus/got/releases/tag/v11.8.5) ### [`v12.0.4`](https://github.com/sindresorhus/got/releases/tag/v12.0.4) [Compare Source](https://github.com/sindresorhus/got/compare/v12.0.3...v12.0.4) - Remove stream lock - unreliable since Node 17.3.0 [`bb8eca9`](https://github.com/sindresorhus/got/commit/bb8eca924c338ca12d5b90d6a26aa28dbddb42ee) ### [`v12.0.3`](https://github.com/sindresorhus/got/releases/tag/v12.0.3) [Compare Source](https://github.com/sindresorhus/got/compare/v12.0.2...v12.0.3) - Allow more types in the `json` option ([#&#8203;2015](https://github.com/sindresorhus/got/issues/2015)) [`eb045bf`](https://github.com/sindresorhus/got/commit/eb045bf) ### [`v12.0.2`](https://github.com/sindresorhus/got/releases/tag/v12.0.2) [Compare Source](https://github.com/sindresorhus/got/compare/v12.0.1...v12.0.2) - Fix `encoding` option with `{responseType: 'json'}` ([#&#8203;1996](https://github.com/sindresorhus/got/issues/1996)) [`0703318`](https://github.com/sindresorhus/got/commit/0703318) ### [`v12.0.1`](https://github.com/sindresorhus/got/releases/tag/v12.0.1) [Compare Source](https://github.com/sindresorhus/got/compare/v12.0.0...v12.0.1) - Fix `nock` compatibility ([#&#8203;1959](https://github.com/sindresorhus/got/issues/1959)) [`bf39d2c`](https://github.com/sindresorhus/got/commit/bf39d2c) - Fix missing export of `Request` TypeScript type ([#&#8203;1940](https://github.com/sindresorhus/got/issues/1940)) [`0f9f2b8`](https://github.com/sindresorhus/got/commit/0f9f2b8) ### [`v12.0.0`](https://github.com/sindresorhus/got/releases/tag/v12.0.0) [Compare Source](https://github.com/sindresorhus/got/compare/v11.8.6...v12.0.0) ##### Introducing Got v12.0.0 :tada: Long time no see! The latest Got version (v11.8.2) was released just in February ❄️ 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](https://github.com/sindresorhus/got?sponsor=1). ##### This package is now pure ESM **Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).** Also see [#&#8203;1789](https://github.com/sindresorhus/got/issues/1789). - **Please don't open issues about `[ERR_REQUIRE_ESM]` and `Must use import to load ES Module` errors.** This is a problem with your setup, not Got. - Please don't open issues about using Got with Jest. Jest does not fully support ESM. - Pretty much any problem with loading this package is a problem with your bundler, test framework, etc, not Got. - If you use TypeScript, you will want to stay on Got v11 until TypeScript 4.6 is out. [Why.](https://github.com/microsoft/TypeScript/issues/46452) - If you use a bundler, make sure it supports ESM and that you have correctly configured it for ESM. - The Got issue tracker is not a support channel for your favorite build/bundler tool. ##### 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 ([#&#8203;1491](https://github.com/sindresorhus/got/issues/1491)) [`49c16ee`](https://github.com/sindresorhus/got/commit/49c16ee54fb19ea7aa77e24ac8c2b602f0aad265) - Remove automatic `content-length` on ReadStream ([#&#8203;1510](https://github.com/sindresorhus/got/issues/1510)) [`472b8ef`](https://github.com/sindresorhus/got/commit/472b8ef9d9fc7713b740981a8b1103a7a9111b26) - Fix promise shortcuts in case of error status code ([#&#8203;1543](https://github.com/sindresorhus/got/issues/1543)) [`ff918fb`](https://github.com/sindresorhus/got/commit/ff918fb6dedb6d8b23421497ec890d43f45121b7) [`1107cc6`](https://github.com/sindresorhus/got/commit/1107cc625e4cc469276483316c48896a21f6251a) - Invert the `methodRewriting` option [`51d88a0`](https://github.com/sindresorhus/got/commit/51d88a0efed56760d116c5b911cea71e3265c787) - Fix `url` not being reused on retry in rare case ([#&#8203;1487](https://github.com/sindresorhus/got/issues/1487)) [`462bc63`](https://github.com/sindresorhus/got/commit/462bc630015064fa4ad4358cf28d24f95e1c958b) - Fix hanging promise on HTTP/2 timeout ([#&#8203;1492](https://github.com/sindresorhus/got/issues/1492)) [`a59fac4`](https://github.com/sindresorhus/got/commit/a59fac415ac013a48b1d514837628a5cf81d6878) - Prevent uncaught ParseErrors on initial successful response ([#&#8203;1527](https://github.com/sindresorhus/got/issues/1527)) [`77df9c3`](https://github.com/sindresorhus/got/commit/77df9c33db5ba3126f54317171e1cfcfceefc3d5) - Throw an error when retrying with consumed body ([#&#8203;1507](https://github.com/sindresorhus/got/issues/1507)) [`62305d7`](https://github.com/sindresorhus/got/commit/62305d77d3428b5c714d21b4bbee68cc75b5f787) - Fix a Node.js 16 bug that hangs Got streams [`06a2d3d`](https://github.com/sindresorhus/got/commit/06a2d3d7d8d4fcc6898b6364d1a18ca1d407092b) - Fix default pagination handling for empty Link header ([#&#8203;1768](https://github.com/sindresorhus/got/issues/1768)) [`1e1e506`](https://github.com/sindresorhus/got/commit/1e1e50647e93d038a4cc6a9bbbfbf61165d8fd39) - Fix incorrect `response.complete` when using cache [`9e15d88`](https://github.com/sindresorhus/got/commit/9e15d887da3b065940bbc8ca38f9c748a0bbc75e) - Fix `Cannot call end` error when `request` returns a `Writable` [`226cc39`](https://github.com/sindresorhus/got/commit/226cc3995f6e16938163ebde24d8762e7dcd15e2) - Fix Request options not being reused on retry [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - Fix types being not compatible with CommonJS [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - Fix `got.paginate does not call init hooks` ([#&#8203;1574](https://github.com/sindresorhus/got/issues/1574)) [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - Generate a new object when passing options to the native `https` module ([#&#8203;1567](https://github.com/sindresorhus/got/issues/1567)) [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - Remove stream reuse check ([#&#8203;1803](https://github.com/sindresorhus/got/issues/1803)) [`9ecc5ee`](https://github.com/sindresorhus/got/commit/9ecc5ee76f77aafd5100520d9d8789c491c8fb24) - Fix merging `searchParams` ([#&#8203;1814](https://github.com/sindresorhus/got/issues/1814)) [`1018c20`](https://github.com/sindresorhus/got/commit/1018c2029eea1f5b75b5120265996f1c0b3c12ae) [`732e9bd`](https://github.com/sindresorhus/got/commit/732e9bd9406ba1c3dd64b445264e891f33fc0254) - Fix unhandled exception when lookup returns invalid IP early ([#&#8203;1737](https://github.com/sindresorhus/got/issues/1737)) [`2453e5e`](https://github.com/sindresorhus/got/commit/2453e5e4213fe036a0108de3e4db414dcf2b4c30) - Fix relative URLs when paginating [`439fb82`](https://github.com/sindresorhus/got/commit/439fb82d2a07cece417a18c47e37cfdeaaf38db7) - Require url to be an instance of URL when paginating ([#&#8203;1818](https://github.com/sindresorhus/got/issues/1818)) [`eda69ff`](https://github.com/sindresorhus/got/commit/eda69ff924a621e499d31cbc590993a32ddb48d3) - Fix `username` and `password` encoding in URL ([#&#8203;1169](https://github.com/sindresorhus/got/issues/1169) [#&#8203;1317](https://github.com/sindresorhus/got/issues/1317)) [`d65d0ca`](https://github.com/sindresorhus/got/commit/d65d0caf627e8d1f5367db34d7d9b55d332c1efb) - Clone raw options [`1c4cefc`](https://github.com/sindresorhus/got/commit/1c4cefc9b49f891712c3758f853d8c6214a1c904) - Fix invalid `afterResponse` return check [`cbc8902`](https://github.com/sindresorhus/got/commit/cbc8902) - Fix `https.alpnProtocols` not having an effect [`e1099fb`](https://github.com/sindresorhus/got/commit/e1099fb) ##### Improvements - Make the `context` option mergeable ([#&#8203;1459](https://github.com/sindresorhus/got/issues/1459)) [`2b8ed1f`](https://github.com/sindresorhus/got/commit/2b8ed1f5a185f30603d24e2ceb8181782de3bc5a) - Add generic argument to AfterResponseHook TypeScript type ([#&#8203;1589](https://github.com/sindresorhus/got/issues/1589)) [`6fc04a9`](https://github.com/sindresorhus/got/commit/6fc04a9b92f07b07b9fba010f2231a90082a039b) - Add read timeout ([#&#8203;1518](https://github.com/sindresorhus/got/issues/1518)) [`e943672`](https://github.com/sindresorhus/got/commit/e9436720fcb32b77d39d5477b420b18083e41c02) *(blocked by [nodejs/node#35923](https://github.com/nodejs/node/issues/35923))* - Improve the pagination API ([#&#8203;1644](https://github.com/sindresorhus/got/issues/1644)) [`2675046`](https://github.com/sindresorhus/got/commit/2675046a83c7f03613f553a8da2912d491be900d) - Change the stackAllItems option to be false by default ([#&#8203;1645](https://github.com/sindresorhus/got/issues/1645)) [`1120370`](https://github.com/sindresorhus/got/commit/1120370e05fd8d9e768677d8474d0c82cf91a6a6) - Throw when afterResponse hook returns an invalid value [`4f21eb3`](https://github.com/sindresorhus/got/commit/4f21eb3db705c90797ef8ee1503704f78fea3c1b) - Add `retry.backoffLimit` option [`41c4136`](https://github.com/sindresorhus/got/commit/41c4136632b9391adb3ac53332b312089bc4dc16) - Add `noise` retry option [`e830077`](https://github.com/sindresorhus/got/commit/e83007704670b5f567ca338c156441f6c569ecb5) - Enable more HTTPS options [`83575d5`](https://github.com/sindresorhus/got/commit/83575d590a119027d319bd9208681973087564a9) [`fe723a0`](https://github.com/sindresorhus/got/commit/fe723a0477dc02785a0b477e3d5f85d0233e5b84) (thanks [@&#8203;Giotino](https://github.com/Giotino)) - Define `error.code` [`f27e8d3`](https://github.com/sindresorhus/got/commit/f27e8d331627074e76e4a9ec85a2c8d0a0625e5f) - Set `options.url` even if some options are invalid [`8d6a680`](https://github.com/sindresorhus/got/commit/8d6a6807883323a83ea5f126ca56b55d9ce5f299) - Improve memory usage when merging options [`2db5ec5`](https://github.com/sindresorhus/got/commit/2db5ec5d366efbbf9e0838eabfa6be774a0518a0) - Support async generators as body [`854430f`](https://github.com/sindresorhus/got/commit/854430f01350811fe8a0ccf20cd820aabfbd3926) [`3df52f3`](https://github.com/sindresorhus/got/commit/3df52f38edbadb45158c37d499817bc5486989c6) - Add missing `once` types for Stream API [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - New error type: `RetryError` which always triggers a new retry when thrown [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - `error.options` is now enumerable [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - `defaults.handlers` don't need a default handler now [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - Add a parser for the `Link` header [`3c23eea`](https://github.com/sindresorhus/got/commit/3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9) - General code improvements [`a5dd9aa`](https://github.com/sindresorhus/got/commit/a5dd9aa37e7891b2620798560799c7f8bd380877) ##### 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`. ```js 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](https://github.com/sindresorhus/got/blob/main/documentation/lets-make-a-plugin.md#authorization) or store them in `options.context` directly. - The `init` hooks are ran only when passing an options object explicitly. ```diff - await got('https://example.com'); // this will *not* trigger the init hooks + await got('https://example.com', {}); // this *will** trigger init hooks ``` - [`options.merge()`](2-options.md) replaced `got.mergeOptions` and `Request.normalizeArguments` ```diff - got.defaults.options = got.mergeOptions(got.defaults.options, {…}); + got.defaults.options.merge(…); ``` This fixes issues like [#&#8203;1450](https://github.com/sindresorhus/got/issues/1450) - Legacy `Url` instances are not supported anymore. You need to use WHATWG URL instead. ```diff - await got(string, {port: 8443}); + const url = new URL(string); + url.port = 8443; + await got(url); ``` - No implicit timeout declaration. ```diff - await got('https://example.com', {timeout: 5000}) + await got('https://example.com', {timeout: {request: 5000}) ``` - No implicit retry declaration. ```diff - 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 ```diff - await got('https://example.com', {dnsLookupIpVersion: 'ipv4'}) + await got('https://example.com', {dnsLookupIpVersion: 4}) ``` - `redirectUrls` and `requestUrl` now give URL instances ```diff - request.requestUrl + request.requestUrl.origin + request.requestUrl.href + request.requestUrl.toString() ``` ```diff - request.redirectUrls[0] + request.redirectUrls[0].origin + request.redirectUrls[0].href + request.redirectUrls[0].toString() ``` - Renamed `request.aborted` to `request.isAborted` ```diff - request.aborted + request.isAborted ``` Reason: consistency with `options.isStream`. - Renamed the `lookup` option to `dnsLookup` ```diff - 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` ```diff 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`. ```diff 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`. ```diff - 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. ```diff - 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`. ```diff await got('https://example.com', { - agent: false + agent: { + http: false, + https: false, + http2: false + } }) ``` - When passing a `url` option when paginating, it now needs to be an absolute URL - the `prefixUrl` option is always reset from now on. The same when retrying in an `afterResponse` hook. ```diff - return {url: '/location'}; + return {url: new URL('/location', response.request.options.url)}; ``` There was confusion around the `prefixUrl` option. It was counterintuitive if used with the Pagination API. For example, it worked fine if the server replied with a relative URL, but if it was an absolute URL then the `prefixUrl` would end up duplicated. In order to fix this, Got now requires an absolute URL - no `prefixUrl` will be applied. - `got.extend(…)` will throw when passing some options that don't accept undefined - undefined no longer retains the old value, as setting undefined explicitly may reset the option ##### Documentation We have redesigned the documentation so it's easier to navigate and find exactly what you are looking for. We hope you like it :heart: ### [`v11.8.6`](https://github.com/sindresorhus/got/releases/tag/v11.8.6) [Compare Source](https://github.com/sindresorhus/got/compare/v11.8.5...v11.8.6) - Destroy request object after successful response </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODEuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE4MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->
chore(deps): update dependency got to v16
Some checks failed
ci/woodpecker/pr/pr-review Pipeline failed
c07b437941
renovate-bot force-pushed renovate/got-16.x from c07b437941
Some checks failed
ci/woodpecker/pr/pr-review Pipeline failed
to f01acdfcbe
Some checks failed
ci/woodpecker/pr/pr-review Pipeline was canceled
2026-11-16 23:03:45 +00:00
Compare
renovate-bot changed title from chore(deps): update dependency got to v16 to chore(deps): update dependency got to v16 - autoclosed 2026-11-17 20:42:21 +00:00
renovate-bot closed this pull request 2026-11-17 20:42:22 +00:00
Some checks failed
ci/woodpecker/pr/pr-review Pipeline was canceled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Personal/backstage!15
No description provided.