Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Function

headers

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.

Since
v15.0.0-RC

How it works

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.

Syntax

await headers()

Returns

A read-only Web Headers object.

Key points

  • The function asynchronously exposes incoming request headers to Server Components.
  • Call headers() without arguments.
  • The result follows the Web Headers interface and is immutable for outgoing-header purposes.
  • Consume the returned promise with await in an async component or with React's use.
  • Use Headers.get() to retrieve a header value by name.

Common mistakes

  • Await headers() or use React's use function; synchronous access is not the current API.
  • Use this API to inspect incoming headers only; it cannot mutate response headers.
  • Reading it depends on the request and prevents the value from being known ahead of time.

Example: Read an incoming request header

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.

When to use it

Request-aware rendering

Inspect the User-Agent or another incoming header while rendering a Server Component.

Authorization inspection

Read an Authorization header for server-side request handling.

Header lookup

Access standard Web Headers methods such as get without modifying the request or response headers.

  • cookies
  • draftMode
  • Headers.get()
  • Server Components
  • Request-time APIs

Source: Functions: headers. Checked 2026-10-15.