Modify Headers With Workers

Hi:

We’re using Cloudlare’s DNS services to route traffic to a set of servers. I’m wondering if it’s possible to use Cloudflare workers to add a header to the web requests before it hits our servers. (We can’t use transform rules because the number of rules we need to apply would exceed what CF allows).

Based on how I understand what Cloudflare workers do, I suspect this is possible but would like to confirm this from experienced users.

If this is possible, can Cloudflare workers access a database to lookup values? I think the Cloudflare KV product allows for this but, again, looking to confirm.

So, the sequence of traffic events would be something like this:

incoming traffic → cfworker → lookup header in cf KV → add header to traffic → traffic hits target web server.

Thanks in advance for your comments and ideas!

Yes, you can do this.

The example Modify request property · Cloudflare Workers docs gives a good base to start from.

It shows how you would add headers to the incoming request before sending that request through to your server.

You would need to add code to read from the KV.

@anon9246926 - thank you for the swift response!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.