ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Inject arbitrary HTTP headers

Open ithinkihaveacat opened this issue 8 years ago • 3 comments

One specific example is an origin-trial header, as used by Chrome.

ithinkihaveacat avatar Apr 25 '17 15:04 ithinkihaveacat

Good idea! And this would be a reason to develop an app (and I'd very much like to have this feature in Cloudflare). But after reading through the documentation I doubt if this is possible.

Adding custom HTTP headers requires the app to run before the page loads, which doesn't seem to be possible given the features outline in the docs. It also contradicts the definition of what a Cloudflare App is:

At its core a Cloudflare app is set of JavaScript and/or CSS files which run on a website, and an install.json file which instructs tools like Cloudflare Apps how to use those files.

Source (bold added).

To add HTTP headers to request, at the minimum the app needs to do:

  • Get the status of the request, because we likely don't need to add headers to requests already cached in the edge node (i.e., cf-cache-status: HIT).
  • Read all of the HTTP headers (both those coming from the origin and those added/changed by Cloudflare based on the configuration).
  • Determine if the custom HTTP header needs to be added (or if it's already there).
  • Return the customised request to the user requesting the file.

I of course hope I'm mistaken, but none of these things seem possible (at this point).

Jos512 avatar Jun 28 '17 08:06 Jos512

Thank you very much for this Good Idea. Its really easy to understand language you have used here. Lot of information for the beginners. This will help me a lot for HTTP header on my website. Keep on writing and share your knowledge for the beginners.

All the Best Alam Freelancer

radiusops avatar Jul 28 '18 15:07 radiusops

This is now possible with Cloudflare Workers. https://www.cloudflare.com/products/cloudflare-workers/

matthewoates avatar Feb 11 '19 20:02 matthewoates