Access HTTP headers values from a request
Use the Request.header()
method to access one individual request header’s value:
app.get('/', (c) => {
c.req.header('User-Agent')
})
You can access all the HTTP headers using the c.req.raw.headers
property:
app.get('/', c => {
console.log(c.req.raw.headers)
})
Change any HTTP header value for a response
You can change any HTTP header value using 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 |
11: | Handling forms COMING SOON |
Are you intimidated by Git? Can’t figure out
merge vs rebase? Are you afraid of screwing up
something any time you have to do something in
Git? Do you rely on ChatGPT or random people’s
answer on StackOverflow to fix your problems?
Your coworkers are tired of explaining Git to
you all the time? Git is something we all need
to use, but few of us really master it. I
created this course to improve your Git (and
GitHub) knowledge at a radical level. Launching
May 21, 2024. Join the waiting list!