-
-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Got 12 improvements #1667
Got 12 improvements #1667
Conversation
So I've benchmarked option normalization... and it's great <3 130k/s when normalizing URL. But when just cloning the options... 1M/s. That means we're bound by native JavaScript performance. Blazing fast. Update: So we're down to 400-500k/s. But that's still better than the current 90-100k. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Oh, and one major thing: this PR uses TS default export. |
Not yet, I can get them added in an hour. Currently I'm finishing my PR in |
Added the tests :) |
Can you open an issue for this? |
This is looking really good! Super nice work as always. 🙌 |
I don't think we should do this though. Can you revert that? While I generally prefer full words, I think it's more important here to use the same name as |
Sure, will do this in a few hours. |
This is a redo of #1521
Fixes #1668 (tested)
Fixes #1663 (tested)
Fixes #1538 (tested)
If this gets merged, we need to open an issue to fix the docs. I'll do them, as well as migration notes etc.
**Note**: By using the `Options` class we introduce a regression! In some cases where option normalization throws `error.options` is `undefined`. ~~This could be solved via **not throwing in the `Options` constructor**, but setting a property e.g. `lastKnownError` instead. That way `error.options` would be defined. It's just a matter what we do consider more friendly.~~ Ok found a better way - let's define `error.options` on the error thrown by the `Options` constructor. Later!Options
)new Options(url | options, options?, defaults?)
Note: Only the first
url
instance is used.Meaning:
got('https://a', {url: 'https://b'})
will actually make a request toa
.If you expect to replace the
url
option, then you need pass the initialurl
like this:got({url: 'https://a', ...otherOptions})
options.merge(newOptions)
replacedgot.mergeOptions
&Request.normalizeArguments
Note: It does NOT merge the
url
option - but it does merge thesearchParameters
optionoptions.url
instead (a URL instance)http
optionstimeout
declaration, use{timeout: {request: 1000}}
insteadretry
declaration, use{retry: {limit: 3}}
insteaddnsLookupIpVersion
is now a number (4
or6
) or undefinedget-stream
(getting a buffer from a stream)core/index.ts
as-promise/index.ts
onCancel
handlers out ofmakeRequest
in order to prevent them being called multiple times (.destroy()
needs to be called only once)Request
class now providesrawBody
ifrequest._noPipe
istrue
(used internally by Promise API)for/entries
to classicfor
loop when iterating overafterResponse
hooks in order to improve performanceWhy:
.entries()
sends a query to get enumerable properties + generates an array - but we don't need that since we already know the enumerable properties since it's an array and we don't need to generate a new oneRequest
options not being reused on retry (needs a testtested)Response
-related stuff tocore/response.ts
core/errors.ts
- you now have to import them directly, meaning you cannot access them viagot.RequestError
RetryError
which always triggers a new retry when thrownwaitForOpenFile
tocore/utils/wait-for-open-file.ts
once
types for Stream APIprivate
sredirectUrls
andrequestUrl
now give URL instancesrequest._beforeError
is now promisifiedrequest.aborted
torequest.isAborted
lookup
option todnsLookup
beforeRetry
hook now accepts only one argument:error
To retrieve:
- the underlying request:
error.request
- the underlying options:
error.options
- current attempt number:
error.request.retryCount + 1
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. To retrieve the original options, use
plainResponse.request.options
.redirect
event now takes two arguments:updatedOptions
andplainResponse
The(reverted; reason: the current API is much nicer)retry
event now takes only one argument:error
To get the attempt count, useerror.request.retryCount + 1
socketPath
option has been removed. Use theunix:
protocol instead.retryWithMergedOptions
function no longer returns aPromise
. Keep in mind that this should be the last function being executed in anafterResponse
hook.error.options
is now enumerabledefaults.handlers
don't need a default handler ((options, next) => next(options)
) now.options.https
tooptions.httpsOptions
_isAboutToError
functionRenamed the(reverted)searchParams
option tosearchParameters
options.agent
tofalse
. To do so, you need to define all theoptions.agent
properties:http
,https
andhttp2
.init
hook now accepts a second argument:self
, which points to anOptions
instanceinit
hooks are ran only when passing an options object explicitly. It's no longer called ongot('https://example.com')
- in order to triggerinit
hooks, you need to callgot('https://example.com', {})
url
option when paginating, it now needs to be an absolute URL - theprefixUrl
option is always reset from now on. The same when retrying in anafterResponse
hook.test/arguments.ts
test/create.ts
test/normalize-arguments.ts
test/hooks.ts
got.extend(...)
will throw when passing some options that don't acceptundefined
-undefined
no longer retains the old value, as settingundefined
explicitly may reset the optionconst {got} = require('got')
To be fixed
default searchParams not properly merged when requesting searchParams is undefined #1610 (might be already fixed - needs a test)request.reusedSocket
#1553path
andpathname
are mutually exclusive" on retry with cache #1567 (might be already fixed - needs a test)beforeRequest
doesn't mergeoptions.json
#1408got.extend
#1117 (maybe, may be postponed to Got 12.x / 13)stream.options
#1405 (docs)Checklist