(defaults: InstanceDefaults)
| 59 | }; |
| 60 | |
| 61 | const create = (defaults: InstanceDefaults): Got => { |
| 62 | defaults = { |
| 63 | options: new Options(undefined, undefined, defaults.options), |
| 64 | handlers: [...defaults.handlers], |
| 65 | mutableDefaults: defaults.mutableDefaults, |
| 66 | }; |
| 67 | |
| 68 | Object.defineProperty(defaults, 'mutableDefaults', { |
| 69 | enumerable: true, |
| 70 | configurable: false, |
| 71 | writable: false, |
| 72 | }); |
| 73 | |
| 74 | const makeRequest = (url: string | URL | OptionsInit | undefined, options: OptionsInit | undefined, defaultOptions: Options, isStream: boolean): GotReturn => { |
| 75 | if (is.plainObject(url)) { |
| 76 | assertNoUrlInOptionsObject(url); |
| 77 | } |
| 78 | |
| 79 | if (is.plainObject(options)) { |
| 80 | assertNoUrlInOptionsObject(options); |
| 81 | } |
| 82 | |
| 83 | // `isStream` is skipped by `merge()`, so set it via the direct setter after construction. |
| 84 | // Avoid a synthetic second merge only for the single-options-object stream form. |
| 85 | const requestUrl = isStream && is.plainObject(url) ? cloneWithProperty(url, 'isStream', true) : url; |
| 86 | const requestOptions = isStream && !is.plainObject(url) && options ? cloneWithProperty(options, 'isStream', true) : options; |
| 87 | |
| 88 | const request = new Request(requestUrl, requestOptions, defaultOptions); |
| 89 | |
| 90 | if (isStream && request.options) { |
| 91 | request.options.isStream = true; |
| 92 | } |
| 93 | |
| 94 | let promise: RequestPromise | undefined; |
| 95 | const urlBeforeHandlers = request.options?.url instanceof URL ? new URL(request.options.url) : undefined; |
| 96 | const boundaryBeforeHandlers = request.options ? getUrlPrefixBoundary(request.options) : undefined; |
| 97 | |
| 98 | const lastHandler = (normalized: Options): GotReturn => { |
| 99 | if ( |
| 100 | urlBeforeHandlers |
| 101 | && boundaryBeforeHandlers |
| 102 | && normalized?.url instanceof URL |
| 103 | && hasUrlOrPrefixUrlBoundaryChanged(normalized, normalized.url, boundaryBeforeHandlers) |
| 104 | ) { |
| 105 | assertUrlHasSameOriginAsPrefixUrlIfNeeded(normalized, normalized.url); |
| 106 | } |
| 107 | |
| 108 | // Note: `options` is `undefined` when `new Options(...)` fails |
| 109 | request.options = normalized; |
| 110 | const shouldReturnStream = normalized?.isStream ?? isStream; |
| 111 | request._noPipe = !shouldReturnStream; |
| 112 | void request.flush(); |
| 113 | |
| 114 | if (shouldReturnStream) { |
| 115 | return request; |
| 116 | } |
| 117 | |
| 118 | promise ??= asPromise(request); |
no test coverage detected
searching dependent graphs…