IncomingRequestCfProperties when proxied

I have a Cloudflare Worker which uses request.cf.country (as outlined in the docs). This works great when the client makes the request directly.

But I also have a server which does server-side rendering. That server calls the same Cloudflare Worker during server-side rendering and I’d like the request.cf.country to match the original visitor’s information, instead of the information of my own server.

Is there a way to pass along the original IP address using a header like X-Forwarded-For to make Cloudflare resolve the request.cf of that IP instead of the one from the request?

1 Like

Instead of calling another worker, can’t you just send the original request (or a reconstructed request) to the appropriate function that handles logic ?

1 Like

I wanted to keep the question short, but I might have ended up providing too little information. I’m offering a feature flagging service, so the request to my Cloudflare Worker is not made within Cloudflare’s infrastructure. I provide a library which my customers integrate and use during server-side rendering.

The full flow is

  1. visitor opens example dot com
  2. example dot com’s Node.js server receives request and starts server-side rendering
  3. during server-side rendering a request to my Cloudflare Worker is made
  4. the response of my Cloudflare Worker is used to generate the example dot com site

As the request to the Cloudflare Worker is made during server-side rendering on the Node.js server, I have access to the original request made by the visitor’s browser. I can forward any information necessary, but I couldn’t find any info of how to use that to my advantage.

If this is not possible I’ll probably pass the original IP along in the request body and use a third-party Geolocation API within the Cloudflare Worker to get the information based on the visitor IP. But it would have been epic if I could let Cloudflare know about the original IP and have it resolve the IncomingRequestCfProperties (country, language, timezone etc) based on that.

I had to use the weird dot com-notation as I’m a new user and I’m not allowed to post “links”.

2 Likes

Is there any news on this?
We have exactly the same question. We already use the X-Forwarded-For header but Cloudflare doesn’t take this into account for the country detection.

@dominik.ferber Did you implement another solution?

1 Like

I ended up not building the feature due to this limitation. It was just a nice-to-have thing for my case.

1 Like