ctx.request.header

A read-only object containing all incoming request headers, with lower-cased field names.

Since Koa 2 Spec ↗

Syntax

ctx.request.header  // or ctx.headers

Returns

Record<string, string | string[]> — An object of all incoming HTTP headers.

Examples

import Koa from 'koa';

const app = new Koa();

app.use(async (ctx) => {
  console.log(ctx.headers['user-agent']);
  console.log(ctx.request.header['accept']);
  ctx.body = 'ok';
});

app.listen(3000);
Output
curl/8.7.1
*/*

Notes

`ctx.headers` and `ctx.request.header` are aliases for the same object. To read a single header in a case-insensitive way, use `ctx.get(field)` which also normalises the `Referrer`/`Referer` alias. The object is the raw Node.js `req.headers`.

See also