useRequestHeaders()

Returns incoming request headers during SSR for proxying or auth checks.

Since Nuxt 3.0 Spec ↗

Syntax

const headers = useRequestHeaders(include?)

Parameters

NameTypeRequiredDescription
include string[] No Optional allowlist of header names to return (lowercased).

Returns

Record<string, string> — The request headers (empty object on the client).

Examples

<script setup lang="ts">
// Forward the cookie header so SSR fetch is authenticated
const headers = useRequestHeaders(['cookie'])
const { data } = await useFetch('/api/me', { headers })
</script>
<script setup lang="ts">
const headers = useRequestHeaders()
const lang = headers['accept-language']
</script>

Notes

Only meaningful during server-side rendering; on the client it returns an empty object because the browser sends headers automatically. Use the `include` allowlist to avoid leaking sensitive headers into client-visible fetches.

See also