headers is an async function that lets you read the HTTP incoming request headers from a Server Component.
app/page.tsx
Parameters
headers takes no parameters.
Returns
headers returns a read-only Web Headers object.
Returns the string value of the named header, or
null if not present.Returns
true if the header exists.Returns an iterator over all header names.
Returns an iterator over all header values.
Returns an iterator over all
[name, value] pairs.Executes a callback for each key/value pair.
Good to know
headersis async and returns a promise. Useasync/awaitor React’suse.- In Next.js 14 and earlier,
headerswas synchronous. Synchronous access still works in Next.js 15 for backwards compatibility, but is deprecated. - The returned
Headersobject is read-only — you cannotsetordeleteheaders. headersis a Request-time API. Using it opts the route into dynamic rendering.
Examples
Forwarding the Authorization header
app/page.tsx
Reading multiple headers
app/page.tsx
Version history
| Version | Changes |
|---|---|
v15.0.0-RC | headers is now async. A codemod is available. |
v13.0.0 | headers introduced. |
