Releases · sindresorhus/got (original) (raw)

Breaking changes

Improvements


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:

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