function headersFieldNamesToLowerCase(headers, throwOnDuplicate) {
  if (!isPlainObject(headers)) {
    throw Error('Headers must be provided as an object')
  }

  const lowerCaseHeaders = {}
  Object.entries(headers).forEach(([fieldName, fieldValue]) => {
    const key = fieldName.toLowerCase()
    if (lowerCaseHeaders[key] !== undefined) {
      if (throwOnDuplicate) {
        throw Error(
          `Failed to convert header keys to lower case due to field name conflict: ${key}`,
        )
      } else {
        debug(
          `Duplicate header provided in request: ${key}. Only the last value can be matched.`,
        )
      }
    }
    lowerCaseHeaders[key] = fieldValue
  })

  return lowerCaseHeaders
}
Return a new object with all field names of the headers lower-cased.

Duplicates throw an error.