AI Workshop: learn to build apps with AI →
Hono: Work with HTTP headers

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Access HTTP header values from a request

Use c.req.header(name) to read a single request header:

app.get('/', (c) => {
  const userAgent = c.req.header('User-Agent')
  return c.text(userAgent ?? '')
})

To read all request headers, use c.req.raw.headers:

app.get('/', c => {
  console.log(c.req.raw.headers)
})

Change any HTTP header value for a response

Set response headers with c.header():

c.header('Content-Type', 'text/html')

Lessons in this unit:

0: Introduction
1: Your first Hono app
2: The Request object
3: Send a response to the client
4: Manage cookies
5: ▶︎ Work with HTTP headers
6: Handling redirects
7: Routing
8: JSX templates
9: Middleware
10: Hono on Node.js