* Return a new object with all field names of the headers lower-cased. * * Duplicates throw an error.
(headers, throwOnDuplicate)
| 116 | * Duplicates throw an error. |
| 117 | */ |
| 118 | function headersFieldNamesToLowerCase(headers, throwOnDuplicate) { |
| 119 | if (!isPlainObject(headers)) { |
| 120 | throw Error('Headers must be provided as an object') |
| 121 | } |
| 122 | |
| 123 | const lowerCaseHeaders = {} |
| 124 | Object.entries(headers).forEach(([fieldName, fieldValue]) => { |
| 125 | const key = fieldName.toLowerCase() |
| 126 | if (lowerCaseHeaders[key] !== undefined) { |
| 127 | if (throwOnDuplicate) { |
| 128 | throw Error( |
| 129 | `Failed to convert header keys to lower case due to field name conflict: ${key}`, |
| 130 | ) |
| 131 | } else { |
| 132 | debug( |
| 133 | `Duplicate header provided in request: ${key}. Only the last value can be matched.`, |
| 134 | ) |
| 135 | } |
| 136 | } |
| 137 | lowerCaseHeaders[key] = fieldValue |
| 138 | }) |
| 139 | |
| 140 | return lowerCaseHeaders |
| 141 | } |
| 142 | |
| 143 | const headersFieldsArrayToLowerCase = headers => [ |
| 144 | ...new Set(headers.map(fieldName => fieldName.toLowerCase())), |
nothing calls this directly
no test coverage detected