Skip to content

Releases: sindresorhus/got

v15.0.2

13 Apr 14:59

Choose a tag to compare

  • Fix stream cookie jar completion race b170125

v15.0.1...v15.0.2

v15.0.1

08 Apr 16:15

Choose a tag to compare

v15.0.0

01 Apr 17:26

Choose a tag to compare

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...v15.0.0

v14.6.6

30 Dec 12:05

Choose a tag to compare

  • 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...v14.6.6

v14.6.5

22 Nov 12:53

Choose a tag to compare

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

v14.6.4...v14.6.5

v14.6.4

14 Nov 08:07

Choose a tag to compare

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

v14.6.3...v14.6.4

v14.6.3

07 Nov 18:51

Choose a tag to compare


v14.6.2...v14.6.3

v14.6.2

02 Nov 10:43

Choose a tag to compare

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

v14.6.1...v14.6.2

v14.6.1

25 Oct 10:29

Choose a tag to compare

  • Fix the TS code not being built in 14.6.0.

v14.6.0...v14.6.1

v14.6.0

16 Oct 16:33

Choose a tag to compare

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...v14.6.0