|
5 | 5 | * @returns Merged headers object |
6 | 6 | */ |
7 | 7 | export function parseAndMergeHeaders( |
8 | | - configHeaders: Record<string, string>, |
9 | | - inputHeaders?: string | Record<string, string> |
| 8 | + configHeaders: Record<string, string>, |
| 9 | + inputHeaders?: string | Record<string, string>, |
10 | 10 | ): Record<string, string> { |
11 | | - // Parse headers if they're provided as a string |
12 | | - let parsedHeaders: Record<string, string> = {}; |
13 | | - |
14 | | - if (typeof inputHeaders === 'string') { |
15 | | - try { |
16 | | - parsedHeaders = JSON.parse(inputHeaders); |
17 | | - } catch (e) { |
18 | | - throw new Error(`Invalid headers JSON: ${e}`); |
19 | | - } |
20 | | - } else if (inputHeaders) { |
21 | | - parsedHeaders = inputHeaders; |
22 | | - } |
23 | | - |
24 | | - // Merge with config headers (config headers are overridden by input headers) |
25 | | - return { ...configHeaders, ...parsedHeaders }; |
| 11 | + // Parse headers if they're provided as a string |
| 12 | + let parsedHeaders: Record<string, string> = {}; |
| 13 | + |
| 14 | + if (typeof inputHeaders === "string") { |
| 15 | + try { |
| 16 | + parsedHeaders = JSON.parse(inputHeaders); |
| 17 | + } catch (e) { |
| 18 | + throw new Error(`Invalid headers JSON: ${e}`); |
| 19 | + } |
| 20 | + } else if (inputHeaders) { |
| 21 | + parsedHeaders = inputHeaders; |
| 22 | + } |
| 23 | + |
| 24 | + // Merge with config headers (config headers are overridden by input headers) |
| 25 | + return { ...configHeaders, ...parsedHeaders }; |
26 | 26 | } |
0 commit comments