Hi Malcolm,
On Mon, May 07, 2012 at 06:19:36PM -0700, Malcolm Handley wrote:
> I'd like to write an ACL that compares the integer value of a cookie
> with a constant. (My goal is to be able to block percentiles of our
> users if we have more traffic than we can handle, so I want to block a
> request if the cookie's value is, say, less then 25.)
>
> I understand that I can do something like
> hdr_sub(cookie) -i <regular expression>
> but that doesn't let me treat the value as an integer and compare it.
>
> I also know about
> hdr_val(<header>)
> but that gives me the entire value of the cookie header, not just the
> value of a particular cookie.
>
> Is there any way that I can do this?
In the next snapshot I hope to be able to push today, there is a new
cookie pattern fetch method which brings a number of "cook_*" ACL keywords.
It does not have cook_val at the moment, but I can check if that's hard
to add or not.
In the mean time, I think that if you manage to rewrite your cookie header
to replace it with a header holding only the value, it might work, though
it's dirty and quite tricky.
Instead, with regex you can actually match integer expressions, it's just
a bit complicated but doable. For instance, a value below 25 might be
defined like this (not tested right now but you get the idea) :
COOK=([0-9]|1[0-9]|2[0-4])([^0-9]|$)
I've been doing this for a long time to extract requests by response times
in logs until I got fed up and wrote halog.
Willy