Is it possible to access requests headers in Pages' functions?

I was trying to access context.request.headers but it's always empty... I'm performing API requests via postman sending custom headers but so far nothing shows up in the response. Here's my code:
export const onRequestPost: PagesFunction<Env> = async (context) => {
return Response.json(context.request.headers);
export const onRequestPost: PagesFunction<Env> = async (context) => {
return Response.json(context.request.headers);
In additon is it possible to get the CF's headers for country and IP in these functions? I know on CF DNS management they do set some CF headers that are attached to the request so you can retrieve the IP and country from these for each visit, I would like to see if I can do the same in CF page functions.
3 Replies
Tonny
TonnyOP7mo ago
bump!
Evil Morty
Evil Morty7mo ago
Cloudflare Docs
Conditional response · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment existing ones …
Tonny
TonnyOP7mo ago
thank you @Evil Morty that worked 👍
Want results from more Discord servers?
Add your server