Redirect Pages Request to Worker only if header is set

Hey, Is there any way to redirect some request that are usually served by Pages to a Worker. I would like to select those request depending on if a HTTP header has a specific value. I know I could use Worker Routes, but that would mean that all request would hit the worker, not only request with that header, which would be overkill since only a minority of request will actually include the header. In the best case it should not do an actual redirect, but just handle the request differently on the server side. Thanks a lot in advance!
2 Replies
Chaika
Chaika7mo ago
Nothing you can do right now except use a Worker Route and have it run on all traffic but not do anything, but in the near future you will be able to use Snippets: https://blog.cloudflare.com/cloudflare-snippets-alpha which are really small/restricted workers but they run according to the ruleset engine, which you could then have only run when a header is equal to a specific value/exists/etc. You could do all your logic in the snippet if it's simple enough, or have the snippet call out to your worker directly.
The Cloudflare Blog
Cloudflare Snippets is now available in alpha
Cloudflare Snippets are available in alpha. Snippets are a simple way of executing a small piece of Javascript on select HTTP requests, using the ruleset engine filtering logic.
DerZade
DerZadeOP7mo ago
Cool thank you so much!
Want results from more Discord servers?
Add your server