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AAE,CAAC;YACtD,OAAO,OAAO,CAAC;QAChB,CAAC;QAED,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;IAChH,CAAC;CACD","sourcesContent":["import {HTTPError} from '../errors/HTTPError.js';\nimport {NonError} from '../errors/NonError.js';\nimport {ForceRetryError} from '../errors/ForceRetryError.js';\nimport type {\n\tInput,\n\tInternalOptions,\n\tNormalizedOptions,\n\tOptions,\n\tSearchParamsInit,\n\tSearchParamsOption,\n} from '../types/options.js';\nimport {type ResponsePromise} from '../types/ResponsePromise.js';\nimport {streamRequest, streamResponse} from '../utils/body.js';\nimport {mergeHeaders, mergeHooks} from '../utils/merge.js';\nimport {normalizeRequestMethod, normalizeRetryOptions} from '../utils/normalize.js';\nimport timeout, {type TimeoutOptions} from '../utils/timeout.js';\nimport delay from '../utils/delay.js';\nimport {type ObjectEntries} from '../utils/types.js';\nimport {findUnknownOptions, hasSearchParameters} from '../utils/options.js';\nimport {isHTTPError, isTimeoutError} from '../utils/type-guards.js';\nimport {\n\tmaxSafeTimeout,\n\tresponseTypes,\n\tstop,\n\tRetryMarker,\n\tsupportsAbortController,\n\tsupportsAbortSignal,\n\tsupportsFormData,\n\tsupportsResponseStreams,\n\tsupportsRequestStreams,\n} from './constants.js';\n\nexport class Ky {\n\tstatic create(input: Input, options: Options): ResponsePromise {\n\t\tconst ky = new Ky(input, options);\n\n\t\tconst function_ = async (): Promise<Response> => {\n\t\t\tif (typeof ky.#options.timeout === 'number' && ky.#options.timeout > maxSafeTimeout) {\n\t\t\t\tthrow new RangeError(`The \\`timeout\\` option cannot be greater than ${maxSafeTimeout}`);\n\t\t\t}\n\n\t\t\t// Delay the fetch so that body method shortcuts can set the Accept header\n\t\t\tawait Promise.resolve();\n\t\t\t// Before using ky.request, _fetch clones it and saves the clone for future retries to use.\n\t\t\t// If retry is not needed, close the cloned request's ReadableStream for memory safety.\n\t\t\tlet response = await ky.#fetch();\n\n\t\t\tfor (const hook of ky.#options.hooks.afterResponse) {\n\t\t\t\t// Clone the response before passing to hook so we can cancel it if needed\n\t\t\t\tconst clonedResponse = ky.#decorateResponse(response.clone());\n\n\t\t\t\tlet modifiedResponse;\n\t\t\t\ttry {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\tmodifiedResponse = await hook(\n\t\t\t\t\t\tky.request,\n\t\t\t\t\t\tky.#getNormalizedOptions(),\n\t\t\t\t\t\tclonedResponse,\n\t\t\t\t\t\t{retryCount: ky.#retryCount},\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Cancel both responses to prevent memory leaks when hook throws\n\t\t\t\t\tky.#cancelResponseBody(clonedResponse);\n\t\t\t\t\tky.#cancelResponseBody(response);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\n\t\t\t\tif (modifiedResponse instanceof RetryMarker) {\n\t\t\t\t\t// Cancel both the cloned response passed to the hook and the current response to prevent resource leaks (especially important in Deno/Bun).\n\t\t\t\t\t// Do not await cancellation since hooks can clone the response, leaving extra tee branches that keep cancel promises pending per the Streams spec.\n\t\t\t\t\tky.#cancelResponseBody(clonedResponse);\n\t\t\t\t\tky.#cancelResponseBody(response);\n\t\t\t\t\tthrow new ForceRetryError(modifiedResponse.options);\n\t\t\t\t}\n\n\t\t\t\t// Determine which response to use going forward\n\t\t\t\tconst nextResponse = modifiedResponse instanceof globalThis.Response ? modifiedResponse : response;\n\n\t\t\t\t// Cancel any response bodies we won't use to prevent memory leaks.\n\t\t\t\t// Uses fire-and-forget since hooks may have cloned the response, creating tee branches that block cancellation.\n\t\t\t\tif (clonedResponse !== nextResponse) {\n\t\t\t\t\tky.#cancelResponseBody(clonedResponse);\n\t\t\t\t}\n\n\t\t\t\tif (response !== nextResponse) {\n\t\t\t\t\tky.#cancelResponseBody(response);\n\t\t\t\t}\n\n\t\t\t\tresponse = nextResponse;\n\t\t\t}\n\n\t\t\tky.#decorateResponse(response);\n\n\t\t\tif (!response.ok && (\n\t\t\t\ttypeof ky.#options.throwHttpErrors === 'function'\n\t\t\t\t\t? ky.#options.throwHttpErrors(response.status)\n\t\t\t\t\t: ky.#options.throwHttpErrors\n\t\t\t)) {\n\t\t\t\tlet error = new HTTPError(response, ky.request, ky.#getNormalizedOptions());\n\n\t\t\t\tfor (const hook of ky.#options.hooks.beforeError) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\terror = await hook(error, {retryCount: ky.#retryCount});\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// If `onDownloadProgress` is passed, it uses the stream API internally\n\t\t\tif (ky.#options.onDownloadProgress) {\n\t\t\t\tif (typeof ky.#options.onDownloadProgress !== 'function') {\n\t\t\t\t\tthrow new TypeError('The `onDownloadProgress` option must be a function');\n\t\t\t\t}\n\n\t\t\t\tif (!supportsResponseStreams) {\n\t\t\t\t\tthrow new Error('Streams are not supported in your environment. `ReadableStream` is missing.');\n\t\t\t\t}\n\n\t\t\t\tconst progressResponse = response.clone();\n\t\t\t\tky.#cancelResponseBody(response);\n\t\t\t\treturn streamResponse(progressResponse, ky.#options.onDownloadProgress);\n\t\t\t}\n\n\t\t\treturn response;\n\t\t};\n\n\t\t// Always wrap in #retry to catch forced retries from afterResponse hooks\n\t\t// Method retriability is checked in #calculateRetryDelay for non-forced retries\n\t\tconst result = ky.#retry(function_)\n\t\t\t.finally(() => {\n\t\t\t\tconst originalRequest = ky.#originalRequest;\n\n\t\t\t\t// Ignore cancellation errors from already-locked or already-consumed streams.\n\t\t\t\tky.#cancelBody(originalRequest?.body ?? undefined);\n\t\t\t\tky.#cancelBody(ky.request.body ?? undefined);\n\t\t\t}) as ResponsePromise;\n\n\t\tfor (const [type, mimeType] of Object.entries(responseTypes) as ObjectEntries<typeof responseTypes>) {\n\t\t\t// Only expose `.bytes()` when the environment implements it.\n\t\t\tif (\n\t\t\t\ttype === 'bytes'\n\t\t\t\t&& typeof (globalThis.Response?.prototype as unknown as {bytes?: unknown})?.bytes !== 'function'\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult[type] = async () => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\tky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);\n\n\t\t\t\tconst response = await result;\n\n\t\t\t\tif (type === 'json') {\n\t\t\t\t\tif (response.status === 204) {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tif (text === '') {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.parseJson) {\n\t\t\t\t\t\treturn options.parseJson(text);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn JSON.parse(text);\n\t\t\t\t}\n\n\t\t\t\treturn response[type]();\n\t\t\t};\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tstatic #normalizeSearchParams(searchParams: SearchParamsOption): SearchParamsOption {\n\t\t// Filter out undefined values from plain objects\n\t\tif (searchParams && typeof searchParams === 'object' && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) {\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries(searchParams).filter(([, value]) => value !== undefined),\n\t\t\t);\n\t\t}\n\n\t\treturn searchParams;\n\t}\n\n\tpublic request: Request;\n\t#abortController?: AbortController;\n\t#retryCount = 0;\n\t// eslint-disable-next-line @typescript-eslint/prefer-readonly -- False positive: #input is reassigned on line 202\n\t#input: Input;\n\treadonly #options: InternalOptions;\n\t#originalRequest?: Request;\n\treadonly #userProvidedAbortSignal?: AbortSignal;\n\t#cachedNormalizedOptions: NormalizedOptions | undefined;\n\n\t// eslint-disable-next-line complexity\n\tconstructor(input: Input, options: Options = {}) {\n\t\tthis.#input = input;\n\n\t\tthis.#options = {\n\t\t\t...options,\n\t\t\theaders: mergeHeaders((this.#input as Request).headers, options.headers),\n\t\t\thooks: mergeHooks(\n\t\t\t\t{\n\t\t\t\t\tbeforeRequest: [],\n\t\t\t\t\tbeforeRetry: [],\n\t\t\t\t\tbeforeError: [],\n\t\t\t\t\tafterResponse: [],\n\t\t\t\t},\n\t\t\t\toptions.hooks,\n\t\t\t),\n\t\t\tmethod: normalizeRequestMethod(options.method ?? (this.#input as Request).method ?? 'GET'),\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tprefixUrl: String(options.prefixUrl || ''),\n\t\t\tretry: normalizeRetryOptions(options.retry),\n\t\t\tthrowHttpErrors: options.throwHttpErrors ?? true,\n\t\t\ttimeout: options.timeout ?? 10_000,\n\t\t\tfetch: options.fetch ?? globalThis.fetch.bind(globalThis),\n\t\t\tcontext: options.context ?? {},\n\t\t};\n\n\t\tif (typeof this.#input !== 'string' && !(this.#input instanceof URL || this.#input instanceof globalThis.Request)) {\n\t\t\tthrow new TypeError('`input` must be a string, URL, or Request');\n\t\t}\n\n\t\tif (this.#options.prefixUrl && typeof this.#input === 'string') {\n\t\t\tif (this.#input.startsWith('/')) {\n\t\t\t\tthrow new Error('`input` must not begin with a slash when using `prefixUrl`');\n\t\t\t}\n\n\t\t\tif (!this.#options.prefixUrl.endsWith('/')) {\n\t\t\t\tthis.#options.prefixUrl += '/';\n\t\t\t}\n\n\t\t\tthis.#input = this.#options.prefixUrl + this.#input;\n\t\t}\n\n\t\tif (supportsAbortController && supportsAbortSignal) {\n\t\t\tthis.#userProvidedAbortSignal = this.#options.signal ?? (this.#input as Request).signal;\n\t\t\tthis.#abortController = new globalThis.AbortController();\n\t\t\tthis.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;\n\t\t}\n\n\t\tif (supportsRequestStreams) {\n\t\t\t// @ts-expect-error - Types are outdated.\n\t\t\tthis.#options.duplex = 'half';\n\t\t}\n\n\t\tif (this.#options.json !== undefined) {\n\t\t\tthis.#options.body = this.#options.stringifyJson?.(this.#options.json) ?? JSON.stringify(this.#options.json);\n\t\t\tthis.#options.headers.set('content-type', this.#options.headers.get('content-type') ?? 'application/json');\n\t\t}\n\n\t\t// To provide correct form boundary, Content-Type header should be deleted when creating Request from another Request with FormData/URLSearchParams body\n\t\t// Only delete if user didn't explicitly provide a custom content-type\n\t\tconst userProvidedContentType = options.headers && new globalThis.Headers(options.headers as HeadersInit).has('content-type');\n\t\tif (\n\t\t\tthis.#input instanceof globalThis.Request\n\t\t\t&& ((supportsFormData && this.#options.body instanceof globalThis.FormData) || this.#options.body instanceof URLSearchParams)\n\t\t\t&& !userProvidedContentType\n\t\t) {\n\t\t\tthis.#options.headers.delete('content-type');\n\t\t}\n\n\t\tthis.request = new globalThis.Request(this.#input, this.#options);\n\n\t\tif (hasSearchParameters(this.#options.searchParams)) {\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst textSearchParams = typeof this.#options.searchParams === 'string'\n\t\t\t\t? this.#options.searchParams.replace(/^\\?/, '')\n\t\t\t\t: new URLSearchParams(Ky.#normalizeSearchParams(this.#options.searchParams) as unknown as SearchParamsInit).toString();\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst searchParams = '?' + textSearchParams;\n\t\t\tconst url = this.request.url.replace(/(?:\\?.*?)?(?=#|$)/, searchParams);\n\n\t\t\t// Recreate request with the updated URL. We already have all options in this.#options, including duplex.\n\t\t\tthis.request = new globalThis.Request(url, this.#options as RequestInit);\n\t\t}\n\n\t\t// If `onUploadProgress` is passed, it uses the stream API internally\n\t\tif (this.#options.onUploadProgress) {\n\t\t\tif (typeof this.#options.onUploadProgress !== 'function') {\n\t\t\t\tthrow new TypeError('The `onUploadProgress` option must be a function');\n\t\t\t}\n\n\t\t\tif (!supportsRequestStreams) {\n\t\t\t\tthrow new Error('Request streams are not supported in your environment. The `duplex` option for `Request` is not available.');\n\t\t\t}\n\n\t\t\tthis.request = this.#wrapRequestWithUploadProgress(this.request, this.#options.body ?? undefined);\n\t\t}\n\t}\n\n\t#calculateDelay(): number {\n\t\tconst retryDelay = this.#options.retry.delay(this.#retryCount);\n\n\t\tlet jitteredDelay = retryDelay;\n\t\tif (this.#options.retry.jitter === true) {\n\t\t\tjitteredDelay = Math.random() * retryDelay;\n\t\t} else if (typeof this.#options.retry.jitter === 'function') {\n\t\t\tjitteredDelay = this.#options.retry.jitter(retryDelay);\n\n\t\t\tif (!Number.isFinite(jitteredDelay) || jitteredDelay < 0) {\n\t\t\t\tjitteredDelay = retryDelay;\n\t\t\t}\n\t\t}\n\n\t\t// Handle undefined backoffLimit by treating it as no limit (Infinity)\n\t\tconst backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;\n\t\treturn Math.min(backoffLimit, jitteredDelay);\n\t}\n\n\tasync #calculateRetryDelay(error: unknown) {\n\t\tthis.#retryCount++;\n\n\t\tif (this.#retryCount > this.#options.retry.limit) {\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wrap non-Error throws to ensure consistent error handling\n\t\tconst errorObject = error instanceof Error ? error : new NonError(error);\n\n\t\t// Handle forced retry from afterResponse hook - skip method check and shouldRetry\n\t\tif (errorObject instanceof ForceRetryError) {\n\t\t\treturn errorObject.customDelay ?? this.#calculateDelay();\n\t\t}\n\n\t\t// Check if method is retriable for non-forced retries\n\t\tif (!this.#options.retry.methods.includes(this.request.method.toLowerCase())) {\n\t\t\tthrow error;\n\t\t}\n\n\t\t// User-provided shouldRetry function takes precedence over all other checks\n\t\tif (this.#options.retry.shouldRetry !== undefined) {\n\t\t\tconst result = await this.#options.retry.shouldRetry({error: errorObject, retryCount: this.#retryCount});\n\n\t\t\t// Strict boolean checking - only exact true/false are handled specially\n\t\t\tif (result === false) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (result === true) {\n\t\t\t\t// Force retry - skip all other validation and return delay\n\t\t\t\treturn this.#calculateDelay();\n\t\t\t}\n\n\t\t\t// If undefined or any other value, fall through to default behavior\n\t\t}\n\n\t\t// Default timeout behavior\n\t\tif (isTimeoutError(error) && !this.#options.retry.retryOnTimeout) {\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (isHTTPError(error)) {\n\t\t\tif (!this.#options.retry.statusCodes.includes(error.response.status)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst retryAfter = error.response.headers.get('Retry-After')\n\t\t\t\t?? error.response.headers.get('RateLimit-Reset')\n\t\t\t\t?? error.response.headers.get('X-RateLimit-Retry-After') // Symfony-based services\n\t\t\t\t?? error.response.headers.get('X-RateLimit-Reset') // GitHub\n\t\t\t\t?? error.response.headers.get('X-Rate-Limit-Reset'); // Twitter\n\t\t\tif (retryAfter && this.#options.retry.afterStatusCodes.includes(error.response.status)) {\n\t\t\t\tlet after = Number(retryAfter) * 1000;\n\t\t\t\tif (Number.isNaN(after)) {\n\t\t\t\t\tafter = Date.parse(retryAfter) - Date.now();\n\t\t\t\t} else if (after >= Date.parse('2024-01-01')) {\n\t\t\t\t\t// A large number is treated as a timestamp (fixed threshold protects against clock skew)\n\t\t\t\t\tafter -= Date.now();\n\t\t\t\t}\n\n\t\t\t\tconst max = this.#options.retry.maxRetryAfter ?? after;\n\t\t\t\t// Don't apply jitter when server provides explicit retry timing\n\t\t\t\treturn after < max ? after : max;\n\t\t\t}\n\n\t\t\tif (error.response.status === 413) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\treturn this.#calculateDelay();\n\t}\n\n\t#decorateResponse(response: Response): Response {\n\t\tif (this.#options.parseJson) {\n\t\t\tresponse.json = async () => this.#options.parseJson!(await response.text());\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t#cancelBody(body: ReadableStream | undefined): void {\n\t\tif (!body) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Ignore cancellation failures from already-locked or already-consumed streams.\n\t\tvoid body.cancel().catch(() => undefined);\n\t}\n\n\t#cancelResponseBody(response: Response): void {\n\t\t// Ignore cancellation failures from already-locked or already-consumed streams.\n\t\tthis.#cancelBody(response.body ?? undefined);\n\t}\n\n\tasync #retry<T extends (...arguments_: any) => Promise<any>>(function_: T): Promise<ReturnType<T> | Response | void> {\n\t\ttry {\n\t\t\treturn await function_();\n\t\t} catch (error) {\n\t\t\tconst ms = Math.min(await this.#calculateRetryDelay(error), maxSafeTimeout);\n\t\t\tif (this.#retryCount < 1) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// Only use user-provided signal for delay, not our internal abortController\n\t\t\tawait delay(ms, this.#userProvidedAbortSignal ? {signal: this.#userProvidedAbortSignal} : {});\n\n\t\t\t// Apply custom request from forced retry before beforeRetry hooks\n\t\t\t// Ensure the custom request has the correct managed signal for timeouts and user aborts\n\t\t\tif (error instanceof ForceRetryError && error.customRequest) {\n\t\t\t\tconst managedRequest = this.#options.signal\n\t\t\t\t\t? new globalThis.Request(error.customRequest, {signal: this.#options.signal})\n\t\t\t\t\t: new globalThis.Request(error.customRequest);\n\n\t\t\t\tthis.#assignRequest(managedRequest);\n\t\t\t}\n\n\t\t\tfor (const hook of this.#options.hooks.beforeRetry) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tconst hookResult = await hook({\n\t\t\t\t\trequest: this.request,\n\t\t\t\t\toptions: this.#getNormalizedOptions(),\n\t\t\t\t\terror: error as Error,\n\t\t\t\t\tretryCount: this.#retryCount,\n\t\t\t\t});\n\n\t\t\t\tif (hookResult instanceof globalThis.Request) {\n\t\t\t\t\tthis.#assignRequest(hookResult);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// If a Response is returned, use it and skip the retry\n\t\t\t\tif (hookResult instanceof globalThis.Response) {\n\t\t\t\t\treturn hookResult;\n\t\t\t\t}\n\n\t\t\t\t// If `stop` is returned from the hook, the retry process is stopped\n\t\t\t\tif (hookResult === stop) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this.#retry(function_);\n\t\t}\n\t}\n\n\tasync #fetch(): Promise<Response> {\n\t\t// Reset abortController if it was aborted (happens on timeout retry)\n\t\tif (this.#abortController?.signal.aborted) {\n\t\t\tthis.#abortController = new globalThis.AbortController();\n\t\t\tthis.#options.signal = this.#userProvidedAbortSignal ? AbortSignal.any([this.#userProvidedAbortSignal, this.#abortController.signal]) : this.#abortController.signal;\n\t\t\t// Recreate request with new signal\n\t\t\tthis.request = new globalThis.Request(this.request, {signal: this.#options.signal});\n\t\t}\n\n\t\tfor (const hook of this.#options.hooks.beforeRequest) {\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tconst result = await hook(\n\t\t\t\tthis.request,\n\t\t\t\tthis.#getNormalizedOptions(),\n\t\t\t\t{retryCount: this.#retryCount},\n\t\t\t);\n\n\t\t\tif (result instanceof Response) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tif (result instanceof globalThis.Request) {\n\t\t\t\tthis.#assignRequest(result);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst nonRequestOptions = findUnknownOptions(this.request, this.#options);\n\n\t\t// Cloning is done here to prepare in advance for retries\n\t\tthis.#originalRequest = this.request;\n\t\tthis.request = this.#originalRequest.clone();\n\n\t\tif (this.#options.timeout === false) {\n\t\t\treturn this.#options.fetch(this.#originalRequest, nonRequestOptions);\n\t\t}\n\n\t\treturn timeout(this.#originalRequest, nonRequestOptions, this.#abortController, this.#options as TimeoutOptions);\n\t}\n\n\t#getNormalizedOptions(): NormalizedOptions {\n\t\tif (!this.#cachedNormalizedOptions) {\n\t\t\tconst {hooks, ...normalizedOptions} = this.#options;\n\t\t\tthis.#cachedNormalizedOptions = Object.freeze(normalizedOptions) as NormalizedOptions;\n\t\t}\n\n\t\treturn this.#cachedNormalizedOptions;\n\t}\n\n\t#assignRequest(request: Request): void {\n\t\tthis.#cachedNormalizedOptions = undefined;\n\t\tthis.request = this.#wrapRequestWithUploadProgress(request);\n\t}\n\n\t#wrapRequestWithUploadProgress(request: Request, originalBody?: BodyInit): Request {\n\t\tif (!this.#options.onUploadProgress || !request.body) {\n\t\t\treturn request;\n\t\t}\n\n\t\treturn streamRequest(request, this.#options.onUploadProgress, originalBody ?? this.#options.body ?? undefined);\n\t}\n}\n"]}