NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #1225 most downloaded on npm
Human-friendly and powerful HTTP request library for Node.js
Last release 1 months ago
30 Aug 2026
Release timing varies
gaps range from 8 days to 3 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
201 releases · first in 2014
Remove the deprecated searchParameters , followRedirects , and auth option stubs 1d233ba
http2-wrapper dependency (#2464) 1e157c4
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.statusCode instead of response.headers[':status'].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.http2-wrapper. It was very buggy anyway.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.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.verbatim address ordering from dns.lookup().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.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.searchParameters, followRedirects, and auth option stubs 1d233ba
Unexpected option: ….OptionsOfUnknownResponseBody type 1d233ba
StrictOptions.QUERY HTTP method (#2466) e3924aa
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 1e157c4timeout.socket now applies during HTTP/2 TLS negotiation and session setup c6bbb8a
request timeout. It now produces a real socket timeout and no longer counts DNS lookup time.cacheable-lookup and http2-wrapper bfc400b 1e157c4request.end() instead of failing the request (#2470) 67919b2Retry-After: 0 instead of falling back to the backoff delay (#2471) d35ce87error.response.body is now complete, decompressed, and decoded with the configured encoding, and a decoding failure no longer masks the original error.followRedirect: false c6bbb8aset-cookie c6bbb8agot.stream finalizing the response before the response event and before piped server response headers are set c6bbb8astrictContentLength counting bytes from responses that were not actually decompressed c6bbb8ahooks.beforeCache along with the other hook arrays on non-mutable defaults 1d233baprefixUrl is changed to a same-origin value, and treat credentials in prefixUrl as explicit dd3b295Remove 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.
h2cThe 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);
}
]
}
});dnsCachednsCache: 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});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 …';
}
]
}
});copyPipedHeadersCredentials 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
}
});One column per quarter.
Add allowAbsoluteUrls option ( #2462 ) 1c88e88
Fix: Preserve request body on cross-origin 307 and 308 redirects ( #2460 ) aee9249
Fix searchParams setter dropping the value when a URL is set ( #2454 ) 5772bf2
Fix: Handle abort signals added by handlers 74e3167
Fix aborting during download progress 11a2202
Fix false ReadError on responses without Content-Length 071ea07
Fix stream cookie jar completion race b170125
Fix init types 20633bc v15.0.0...v15.0.1
Remove promise cancel API a06ac6c
promise.cancel() is gone. Use the signal option with AbortController instead.isStream option c241c6c
got.stream() directly.FormData global 670b228
FormData global directly (available in Node.js 18+).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
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
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}}.{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
url property is no longer present on the options object passed to hooks. Use response.url or request.requestUrl instead.text/json bodies incrementally for lower peak memory usage c9a95b1uploadProgress now emits granular per-chunk events for json and form request bodies 13c889dpromise.cancel() with AbortControllerBefore:
const promise = got(url);
promise.cancel();After:
const controller = new AbortController();
const promise = got(url, {signal: controller.signal});
controller.abort();isStream: true with got.stream()Before:
got(url, {isStream: true});After:
got.stream(url);form-data / form-data-encoder with native FormDataBefore:
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});Buffer usage to Uint8Arrayresponse.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 defaultIf 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 defaultIf 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;
},
},
});If you pipe streams into Got and rely on automatic header forwarding (e.g. Content-Type), re-enable it:
got.extend({copyPipedHeaders: true});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.
Fix stream auto-end for empty PATCH/DELETE/OPTIONS 4d5168c
got.streamdoes not auto-end forOPTIONS,DELETE, orPATCHso you can pipe or write a body without gettingwrite after end. Callstream.end()when you are not piping a body.
Fix TypeScript type inference for got.extend() with responseType option f7ab6e9
got.extend() with responseType option f7ab6e9https://github.com/sindresorhus/got/compare/v14.6.4...v14.6.5
Fix dnsLookup option type to accept Node.js dns.lookup 47c3155
dnsLookup option type to accept Node.js dns.lookup 47c3155https://github.com/sindresorhus/got/compare/v14.6.3...v14.6.4
Fix socket reuse timing and DNS timing fb03d84 61d5e3b
https://github.com/sindresorhus/got/compare/v14.6.2...v14.6.3
Fix path segments containing colons being misidentified as absolute URLs 0a16a9c
https://github.com/sindresorhus/got/compare/v14.6.1...v14.6.2
Fix the TS code not being built in 14.6.0.
https://github.com/sindresorhus/got/compare/v14.6.0...v14.6.1
Add retryCount to beforeRequest hook context 91cdc48
beforeCache hook 1c3a041retryCount to beforeRequest hook context 91cdc48HTTPError message to include method and URL 6dd7574beforeError hook 1c71194strictContentLength option 4206f0ehttps.secureOptions option 7ec1714copyPipedHeaders option to control automatic header copying from piped streams d83daddstream.isReadonly property to detect read-only streams 030dfbbbeforeRetry hooks bf84d36beforeError hook not being called for ERR_UNSUPPORTED_PROTOCOL error fb86418prefixUrl in hooks 9725fbdcontent-length when piping decompressed responses 30b3b79afterResponse hook validation to allow null body values 60a4419timings.end being undefined when stream is destroyed before completion 4e75679I managed to get it almost down to zero issues! 🎉
https://github.com/sindresorhus/got/compare/v14.5.0...v14.6.0
Add retry.enforceRetryRules option to fix statusCodes/limit bypassing 7c0aee6
retry.enforceRetryRules option to fix statusCodes/limit bypassing 7c0aee6serverName HTTPS option cdaab63preserveHooks option for retryWithMergedOptions 1abeba4Iterable and AsyncIterable as request body b65b0e1downloadProgress firing for redirect responses 9ec6ff0false as agent value 6961284https://github.com/sindresorhus/got/compare/v14.4.9...v14.5.0
Fix hang with responses containing content-encoding headers but no body cc434bc
content-encoding headers but no body cc434bchttps://github.com/sindresorhus/got/compare/v14.4.8...v14.4.9
Fix infinite loop when retrying with request.options in afterResponse hook dad6a91
request.options in afterResponse hook dad6a91https://github.com/sindresorhus/got/compare/v14.4.7...v14.4.8
Fix: Gracefully handle undefined request (#2404) 06029e0
https://github.com/sindresorhus/got/compare/v14.4.6...v14.4.7
Fix timeout error firing even though it's cancelled (#2399) 7a92064
https://github.com/sindresorhus/got/compare/v14.4.5...v14.4.6
Fix a crash with Got accessing a non-existent request (#2391) c079b93
https://github.com/sindresorhus/got/compare/v14.4.4...v14.4.5
Fix support for AbortSignal#timeout() (#2388) 92b378e
AbortSignal#timeout() (#2388) 92b378ehttps://github.com/sindresorhus/got/compare/v14.4.3...v14.4.4
Fix cache with HTTP2 (#2380) f2f8cb2
https://github.com/sindresorhus/got/compare/v14.4.2...v14.4.3
Fix handling of invalid arguments (#2367) f44ef43
https://github.com/sindresorhus/got/compare/v14.4.1...v14.4.2
https://github.com/sindresorhus/got/compare/v14.4.0...v14.4.1
https://github.com/sindresorhus/got/compare/v14.4.0...v14.4.1
Improve TypeScript types with generic extend (#2353) 15ca4a0
https://github.com/sindresorhus/got/compare/v14.3.0...v14.4.0
https://github.com/sindresorhus/got/compare/v14.2.1...v14.3.0
https://github.com/sindresorhus/got/compare/v14.2.1...v14.3.0
Fix error handling when UTF-8 decoding fails (#2336) c81a611
https://github.com/sindresorhus/got/compare/v14.2.0...v14.2.1
Add cause property with the original error to RequestError (#2327) 4cbd01d
cause property with the original error to RequestError (#2327) 4cbd01dhttps://github.com/sindresorhus/got/compare/v14.1.0...v14.2.0
Allow typing the body of a RequestError response (#2325) 5e4f6ff
RequestError response (#2325) 5e4f6ffhttps://github.com/sindresorhus/got/compare/v14.0.0...v14.1.0
Require Node.js 20 (#2313) a004263
followRedirect option accept a function (#2306) 7c3f147https://github.com/sindresorhus/got/compare/v13.0.0...v14.0.0
As a reminder, Got continues to require ESM. For TypeScript users, this includes having `"module": "node16", "moduleResolution": "node16"` in your tsc
As a reminder, Got continues to require ESM. For TypeScript users, this includes having "module": "node16", "moduleResolution": "node16" in your tsconfig.
enableUnixSockets option to be false by default 852c312
undefined for options (#2258) 1cefe8bhttps://github.com/sindresorhus/got/compare/v12.6.1...v13.0.0
Fix get-stream import statement (#2266) 67d5039
get-stream import statement (#2266) 67d5039https://github.com/sindresorhus/got/compare/v12.6.0...v12.6.1
Update dependencies 88c88fb 979272e
https://github.com/sindresorhus/got/compare/v12.5.3...v12.6.0
Fix abort event listeners not always being cleaned up (#2162) 3cc40b5
https://github.com/sindresorhus/got/compare/v12.5.2...v12.5.3
Improve TypeScript 4.9 compatibility (#2163) 39f83b6
https://github.com/sindresorhus/got/compare/v12.5.1...v12.5.2
Fix compatibility with TypeScript and ESM 3b3ea67
https://github.com/sindresorhus/got/compare/v12.5.0...v12.5.1
Disable method rewriting on 307 and 308 status codes (#2145) e049e94
https://github.com/sindresorhus/got/compare/v12.4.1...v12.5.0
Fix options.context being not extensible b671480715dbbff908e9a385f5e714570c663cd7
options.context being not extensible b671480715dbbff908e9a385f5e714570c663cd7uploadProgress after promise cancelation 693de217b030816f574d6e4cb505ee2e77b21c29https://github.com/sindresorhus/got/compare/v12.4.0...v12.4.1
Support FormData without known length (#2120) 850773c
beforeError hooks with HTTPError if the throwHttpErrors option is false (#2104) 3927348https://github.com/sindresorhus/got/compare/v12.3.1...v12.4.0
Don't freeze signal when freezing Options (#2100) 43b1467
https://github.com/sindresorhus/got/compare/v12.3.0...v12.3.1
Add .off() method for events (#2092) 88056be
.off() method for events (#2092) 88056behttps://github.com/sindresorhus/got/compare/v12.2.0...v12.3.0
Support `AbortController` (#2020) 6a6d2a9
AbortController (#2020) 6a6d2a9enableUnixSockets option (#2062) 461b3d4https://github.com/sindresorhus/got/compare/v12.1.0...v12.2.0
Add response.ok (#2043) 22d58fb
response.ok (#2043) 22d58fb
{throwHttpErrors: false}https://github.com/sindresorhus/got/compare/v12.0.4...v12.1.0
Remove stream lock - unreliable since Node 17.3.0 bb8eca924c338ca12d5b90d6a26aa28dbddb42ee
Allow more types in the json option (#2015) eb045bf
json option (#2015) eb045bfhttps://github.com/sindresorhus/got/compare/v12.0.2...v12.0.3
Fix encoding option with {responseType: 'json'} (#1996) 0703318
encoding option with {responseType: 'json'} (#1996) 0703318https://github.com/sindresorhus/got/compare/v12.0.1...v12.0.2
Fix nock compatibility (#1959) bf39d2c
nock compatibility (#1959) bf39d2cRequest TypeScript type (#1940) 0f9f2b8https://github.com/sindresorhus/got/compare/v12.0.0...v12.0.1
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
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.
Please read this. Also see https://github.com/sindresorhus/got/issues/1789.
[ERR_REQUIRE_ESM] and Must use import to load ES Module errors. This is a problem with your setup, not Got.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.
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.
Woah, we possibly couldn't make a release if we didn't fix some bugs!
content-length on ReadStream (#1510) 472b8ef9d9fc7713b740981a8b1103a7a9111b26methodRewriting option 51d88a0efed56760d116c5b911cea71e3265c787url not being reused on retry in rare case (#1487) 462bc630015064fa4ad4358cf28d24f95e1c958bresponse.complete when using cache 9e15d887da3b065940bbc8ca38f9c748a0bbc75eCannot call end error when request returns a Writable 226cc3995f6e16938163ebde24d8762e7dcd15e2got.paginate does not call init hooks (#1574) 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9https module (#1567) 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9searchParams (#1814) 1018c2029eea1f5b75b5120265996f1c0b3c12ae 732e9bd9406ba1c3dd64b445264e891f33fc0254username and password encoding in URL (#1169 #1317) d65d0caf627e8d1f5367db34d7d9b55d332c1efbafterResponse return check cbc8902https.alpnProtocols not having an effect e1099fbcontext option mergeable (#1459) 2b8ed1f5a185f30603d24e2ceb8181782de3bc5aretry.backoffLimit option 41c4136632b9391adb3ac53332b312089bc4dc16noise retry option e83007704670b5f567ca338c156441f6c569ecb5error.code f27e8d331627074e76e4a9ec85a2c8d0a0625e5foptions.url even if some options are invalid 8d6a6807883323a83ea5f126ca56b55d9ce5f299once types for Stream API 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9RetryError which always triggers a new retry when thrown 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9error.options is now enumerable 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9defaults.handlers don't need a default handler now 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9Link header 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9Option 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
}
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.
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
options.merge() replaced got.mergeOptions and Request.normalizeArguments- got.defaults.options = got.mergeOptions(got.defaults.options, {…});
+ got.defaults.options.merge(…);
This fixes issues like #1450
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);
- await got('https://example.com', {timeout: 5000})
+ await got('https://example.com', {timeout: {request: 5000})
- 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()
request.aborted to request.isAborted- request.aborted
+ request.isAborted
Reason: consistency with options.isStream.
lookup option to dnsLookup- await got('https://example.com', {lookup: cacheable.lookup})
+ await got('https://example.com', {dnsLookup: cacheable.lookup})
beforeRetry hook now accepts only two arguments: error and retryCountawait 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).
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]
}
]
}
})
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.
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')
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.
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
+ }
})
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 optionWe have redesigned the documentation so it's easier to navigate and find exactly what you are looking for. We hope you like it :heart:
Fix invalid afterResponse return check cbc8902
afterResponse return check cbc8902retryWithMergedOptions valid hooks (#1832) 15c30eegot-scraping to Got plugins in readme (#1823) 7805501https.alpnProtocols not having an effect e1099fbClone raw options 1c4cefc9b49f891712c3758f853d8c6214a1c904
Previously Got 12 was freezing the options instead of cloning, but it seems this is too breaking. Reverted option freezing so the behavior matches Got 11.
v12.0.0-beta.2 introduces more stability fixes! Yay!
v12.0.0-beta.2 introduces more stability fixes! Yay!
searchParams (#1814) 1018c2029eea1f5b75b5120265996f1c0b3c12ae 732e9bd9406ba1c3dd64b445264e891f33fc0254username and password encoding in URL (#1169 #1317) d65d0caf627e8d1f5367db34d7d9b55d332c1efbWe are pleased to announce Got v12.0.0 beta 1! :tada: It's been a year and three months since Got 11 was released, and the latest Got version (v11.8.2
We are pleased to announce Got v12.0.0 beta 1! :tada: It's been a year and three months since Got 11 was released, and the latest Got version (v11.8.2) was released just in February ❄️ During that time, we have been working hard on squashing bugs and improving overall experience.
If you find Got useful, you might want to sponsor the Got maintainers.
Please read this. Also see https://github.com/sindresorhus/got/issues/1789.
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.
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.
Woah, we possibly couldn't make a release if we didn't fix some bugs!
content-length on ReadStream (#1510) 472b8ef9d9fc7713b740981a8b1103a7a9111b26methodRewriting option 51d88a0efed56760d116c5b911cea71e3265c787url not being reused on retry in rare case (#1487) 462bc630015064fa4ad4358cf28d24f95e1c958bresponse.complete when using cache 9e15d887da3b065940bbc8ca38f9c748a0bbc75eCannot call end error when request returns a Writable 226cc3995f6e16938163ebde24d8762e7dcd15e2got.paginate does not call init hooks (#1574) 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9https module (#1567) 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9context option mergeable (#1459) 2b8ed1f5a185f30603d24e2ceb8181782de3bc5aretry.backoffLimit option 41c4136632b9391adb3ac53332b312089bc4dc16noise retry option e83007704670b5f567ca338c156441f6c569ecb5error.code f27e8d331627074e76e4a9ec85a2c8d0a0625e5foptions.url even if some options are invalid 8d6a6807883323a83ea5f126ca56b55d9ce5f299once types for Stream API 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9RetryError which always triggers a new retry when thrown 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9error.options is now enumerable 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9defaults.handlers don't need a default handler now 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9Link header 3c23eea5a096f6f8ea0edf3e2a27e1caca88acf9Option 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
}
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.
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
options.merge() replaced got.mergeOptions and Request.normalizeArguments- got.defaults.options = got.mergeOptions(got.defaults.options, {…});
+ got.defaults.options.merge(…);
This fixes issues like #1450
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);
- await got('https://example.com', {timeout: 5000})
+ await got('https://example.com', {timeout: {request: 5000})
- 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()
request.aborted to request.isAborted- request.aborted
+ request.isAborted
Reason: consistency with options.isStream.
lookup option to dnsLookup- await got('https://example.com', {lookup: cacheable.lookup})
+ await got('https://example.com', {dnsLookup: cacheable.lookup})
beforeRetry hook now accepts only two arguments: error and retryCountawait 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).
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]
}
]
}
})
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.
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')
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.
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
+ }
})
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 optionWe have redesigned the documentation so it's easier to navigate and find exactly what you are looking for. We hope you like it :heart:
Note:
- The TypeScript documentation hasn't been updated yet. It will be updated on a stable release.
Destroy request object after successful response
https://github.com/sindresorhus/got/compare/v11.8.5...v11.8.6
Backport security fix https://github.com/sindresorhus/got/commit/861ccd9ac2237df762a9e2beed7edd88c60782dc
https://github.com/sindresorhus/got/compare/v11.8.4...v11.8.5
Bump cacheable-request dependency (#1921) 9463bb6
HTTPError missing .code property (#1739) 0e167b8https://github.com/sindresorhus/got/compare/v11.8.2...v11.8.3
Make the dnsCache option lazy (#1529) 3bd245f This slightly improves Got startup performance and fixes an issue with Jest.
dnsCache option lazy (#1529) 3bd245f
This slightly improves Got startup performance and fixes an issue with Jest.https://github.com/sindresorhus/got/compare/v11.8.1...v11.8.2
Do not throw on custom stack traces (#1491) 4c815c3a609eb74d0eb139414d9996b4f65dc3c0
Your coding agent can read these notes before it upgrades. Set up the MCP server →