Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(ssr): ensure useRequestHeaders are case-insensitive (#8805)
Browse files Browse the repository at this point in the history
Co-authored-by: Haruaki OTAKE <aaharu@hotmail.com>
  • Loading branch information
manniL and aaharu committed Nov 9, 2022
1 parent 15d4cea commit 0cf0f59
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/composables/ssr.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 0cf0f59

Please sign in to comment.