fix(ssr): ensure useRequestHeaders are case-insensitive (#8805)

Co-authored-by: Haruaki OTAKE <aaharu@hotmail.com>
This commit is contained in:
Alexander Lichter 2022-11-09 10:04:19 +01:00 committed by GitHub
parent 15d4cea97e
commit 0cf0f59bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,13 +2,13 @@
import type { H3Event } from 'h3'
import { useNuxtApp, NuxtApp } from '../nuxt'
export function useRequestHeaders<K extends string = string> (include: K[]): Record<K, string | undefined>
export function useRequestHeaders<K extends string = string> (include: K[]): Record<Lowercase<K>, string | undefined>
export function useRequestHeaders (): Readonly<Record<string, string | undefined>>
export function useRequestHeaders (include?: any[]) {
if (process.client) { return {} }
const headers = useNuxtApp().ssrContext?.event.req.headers ?? {}
if (!include) { return headers }
return Object.fromEntries(include.filter(key => headers[key]).map(key => [key, headers[key]]))
return Object.fromEntries(include.map(key => key.toLowerCase()).filter(key => headers[key]).map(key => [key, headers[key]]))
}
export function useRequestEvent (nuxtApp: NuxtApp = useNuxtApp()): H3Event {