Adding request header before WAF

Hi,

I have a complicated ruleset for rate limiting. Now there’s a new requirement to dynamically route to other servers with criteria very similar to the rate limiting rules. I’m trying to use load balancing for that.
I have a rule in “header modification” phase, and then I look for this header in the rule where I dynamically route, in the “load balancing” phase.

Optimally, I want to perform the rule check in a worker, instead of using the expression builder, and I want it to affect both WAF and load-balancing.

If the order of the phases was: worker, WAF, Load balancing, optimally I would like to do the descision making in the worker, by setting request headers, and then for the other phases to have rudimentry rules (if rate limit requested, do a rate limit, if dynamic routing request, do dynamic routing, etc.).

But alas, that’s not the order.

Any idea on how should I apporach this?

Summary of the requirements:

  1. Decide using a rule if we should rate limit, and if we should do dynamic routing, BEFORE the WAF phase.
  2. WAF phase to look at a request header created in step #1 and act accordingly
  3. Load balancing phase to look at a request header created in step #1 and act accordingly

Thanks!

Tal