* @param {Record } * @returns {Record }
(opts)
| 35 | * @returns {Record<string, string[] | string>} |
| 36 | */ |
| 37 | function normalizeHeaders (opts) { |
| 38 | let headers |
| 39 | if (opts.headers == null) { |
| 40 | headers = {} |
| 41 | } else if (typeof opts.headers === 'object') { |
| 42 | headers = {} |
| 43 | |
| 44 | if (hasSafeIterator(opts.headers)) { |
| 45 | for (const x of opts.headers) { |
| 46 | if (!Array.isArray(x)) { |
| 47 | throw new Error('opts.headers is not a valid header map') |
| 48 | } |
| 49 | const [key, val] = x |
| 50 | if (typeof key !== 'string' || typeof val !== 'string') { |
| 51 | throw new Error('opts.headers is not a valid header map') |
| 52 | } |
| 53 | headers[key.toLowerCase()] = val |
| 54 | } |
| 55 | } else { |
| 56 | for (const key of Object.keys(opts.headers)) { |
| 57 | headers[key.toLowerCase()] = opts.headers[key] |
| 58 | } |
| 59 | } |
| 60 | } else { |
| 61 | throw new Error('opts.headers is not an object') |
| 62 | } |
| 63 | |
| 64 | return headers |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @param {any} key |
nothing calls this directly
no test coverage detected