mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
perf(nuxt): avoid multiple iterations in useRequestHeaders
(#24853)
This commit is contained in:
parent
9de21173a8
commit
97a6715b2c
@ -13,9 +13,17 @@ export function useRequestHeaders (): Readonly<Record<string, string>>
|
||||
export function useRequestHeaders (include?: any[]) {
|
||||
if (import.meta.client) { return {} }
|
||||
const event = useRequestEvent()
|
||||
const headers = event ? getRequestHeaders(event) : {}
|
||||
if (!include) { return headers }
|
||||
return Object.fromEntries(include.map(key => key.toLowerCase()).filter(key => headers[key]).map(key => [key, headers[key]]))
|
||||
const _headers = event ? getRequestHeaders(event) : {}
|
||||
if (!include || !event) { return _headers }
|
||||
const headers = Object.create(null)
|
||||
for (const _key of include) {
|
||||
const key = _key.toLowerCase()
|
||||
const header = _headers[key]
|
||||
if (header) {
|
||||
headers[key] = header
|
||||
}
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
export function useRequestHeader(header: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user