* Creates a new Headers object and copies headers from fetch arguments * @param fetchArgs Original fetch arguments containing input and options * @returns A new Headers object with copied headers from input and options
(fetchArgs: Parameters<Fetch>)
| 92 | * @returns A new Headers object with copied headers from input and options |
| 93 | */ |
| 94 | function copyHeaders(fetchArgs: Parameters<Fetch>): Headers { |
| 95 | const [input, options = {}] = fetchArgs; |
| 96 | |
| 97 | // Start with base headers from input if it's a Request, otherwise empty Headers |
| 98 | const headers = new Headers( |
| 99 | input instanceof Request ? input.headers : undefined, |
| 100 | ); |
| 101 | |
| 102 | // Copy any headers from options, overriding existing values |
| 103 | if (options.headers) { |
| 104 | Object.entries(options.headers).forEach(([key, value]) => { |
| 105 | headers.set(key, value); |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | return headers; |
| 110 | } |
| 111 | |
| 112 | function buildTokenAuthConfig(token: string): TokenAuthConfig { |
| 113 | return { token }; |
no test coverage detected