(resource, init)
| 215 | } |
| 216 | |
| 217 | async #parseFetchOptions(resource, init) { |
| 218 | let url; |
| 219 | let options = { ...init }; |
| 220 | |
| 221 | if (resource instanceof Request) { |
| 222 | url = resource.url; |
| 223 | options = { |
| 224 | method: resource.method, |
| 225 | headers: resource.headers, |
| 226 | body: resource.body, |
| 227 | ...init, |
| 228 | }; |
| 229 | if (!('redirect' in options) && resource.redirect !== 'follow') { |
| 230 | options.redirect = resource.redirect; |
| 231 | } |
| 232 | } else if (resource.toString) { |
| 233 | url = resource.toString(); |
| 234 | } else { |
| 235 | url = resource; |
| 236 | } |
| 237 | |
| 238 | options.headers = canonicalizeHeaders(options?.headers); |
| 239 | |
| 240 | if (options?.body) { |
| 241 | const { body: requestBody, type } = await this.#serializeBody(options.body); |
| 242 | options.body = requestBody; |
| 243 | if (type && !options.headers.some(([key]) => key.toLowerCase() === 'content-type')) { |
| 244 | options.headers.push(['Content-Type', type]); |
| 245 | } |
| 246 | } else { |
| 247 | delete options.body; |
| 248 | } |
| 249 | |
| 250 | return { |
| 251 | url: url, |
| 252 | method: options.method, |
| 253 | headers: options.headers, |
| 254 | body: options.body, |
| 255 | timeout: options.timeout, |
| 256 | forceHttp3: options.forceHttp3, |
| 257 | signal: options.signal, |
| 258 | redirect: options.redirect, |
| 259 | }; |
| 260 | } |
| 261 | |
| 262 | async fetch(resource, init) { |
| 263 | const { url: initialUrl, signal, redirect, ...options } = await this.#parseFetchOptions(resource, init); |
no test coverage detected