Request-aware rendering
Inspect the User-Agent or another incoming header while rendering a Server Component.
Next.js 16+ · Function
headers() asynchronously reads incoming HTTP request headers in a Server Component. It returns a read-only Web Headers object and is a request-time API.
Call the async headers function in a Server Component to obtain a read-only Web Headers object for the incoming request, then use standard Headers methods such as get. Because it is request-time data, its values are not known during build-time rendering.
await headers()A read-only Web Headers object.
import { headers } from 'next/headers'
export default async function Page() {
const requestHeaders = await headers()
const userAgent = requestHeaders.get('user-agent') ?? 'unknown'
return <p>User agent: {userAgent}</p>
}Reads the incoming request's User-Agent header in an async Server Component and renders it.
Inspect the User-Agent or another incoming header while rendering a Server Component.
Read an Authorization header for server-side request handling.
Access standard Web Headers methods such as get without modifying the request or response headers.
cookiesdraftModeHeaders.get()Server ComponentsRequest-time APIs