mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(ssr): ensure useRequestHeaders are case-insensitive (#8805)
Co-authored-by: Haruaki OTAKE <aaharu@hotmail.com>
This commit is contained in:
parent
15d4cea97e
commit
0cf0f59bc5
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user