headers()
Reads incoming request headers in Server Components and handlers.
Syntax
import { headers } from 'next/headers'; const h = await headers() Returns
Promise<ReadonlyHeaders> — A read-only Web Headers instance.
Examples
import { headers } from 'next/headers'
export default async function Page() {
const headersList = await headers()
const ua = headersList.get('user-agent')
return <p>UA: {ua}</p>
}
import { headers } from 'next/headers'
export async function GET() {
const h = await headers()
const auth = h.get('authorization')
return Response.json({ hasAuth: Boolean(auth) })
}
Notes
Next 15: `headers()` is async — `await` it. It returns a read-only
`Headers` object; you cannot mutate request headers (set response
headers via the `Response`/`NextResponse`). Using it opts the route
into dynamic rendering. Server-only.