( reqHeaders: Record<string, string | string[] | undefined | number>, )
| 66 | * Convert common request headers to a simple dictionary. |
| 67 | */ |
| 68 | export function headersToDict( |
| 69 | reqHeaders: Record<string, string | string[] | undefined | number>, |
| 70 | ): Record<string, string> { |
| 71 | const headers: Record<string, string> = Object.create(null); |
| 72 | |
| 73 | try { |
| 74 | Object.entries(reqHeaders).forEach(([key, value]) => { |
| 75 | if (typeof value === 'string') { |
| 76 | headers[key] = value; |
| 77 | } else if (typeof value === 'number') { |
| 78 | headers[key] = String(value); |
| 79 | } |
| 80 | }); |
| 81 | } catch { |
| 82 | // just return the empty headers |
| 83 | } |
| 84 | |
| 85 | return headers; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Converts a `Request` object that implements the `Web Fetch API` (https://developer.mozilla.org/en-US/docs/Web/API/Headers) into the format that the `RequestData` integration understands. |
no test coverage detected