Forum Discussion

atoth's avatar
atoth
Icon for Cirrus rankCirrus
Sep 24, 2016

http::header value question

I'm trying to write an irule where based on the value of a custom http header it redirects to different servers. Its a little clunky, but when I figure where I'm going I put the values in datagroup with a matchclass statement. The header abc is a string with bunch of numbers, and the irule looks at the last number and redirects based on that. Anyway, this is what I have, and unfortunately, after trying a bunch of things, I still haven't been able to save it without syntax errors.

when HTTP_REQUEST {
if { ([HTTP::header value abc] ends_with "1") OR ([HTTP::header value abc] ends_with "2") OR ([HTTP::header value abc] ends_with "3") OR ([HTTP::header value abc] ends_with "4") OR ([HTTP::header value abc] ends_with "5")} {
node 1.1.1.1 443
} elseif { ([HTTP::header value abc] ends_with "6") OR ([HTTP::header value abc] ends_with "7") OR ([HTTP::header value abc] ends_with "8") OR ([HTTP::header value abc] ends_with "9") OR ([HTTP::header value abc] ends_with "0")} {
node 2.2.2.2 443
} else {
default_pool
}
}

4 Replies

  • Hi Atoth,

    I don't think that a data-group is the right choice for this task. The possible values are not that much and are also rather static.

    But you may try the syntax below. It uses the

    [switch]
    command with
    -glob
    *[01234]
    and
    *[56789]
    patterns to route your request based on the last digit of the given header value...

    when HTTP_REQUEST {
        switch -glob -- [HTTP::header value abc] {
            "*[01234]" { node 1.1.1.1 443 }
            "*[56789]" { node 2.2.2.2 443 }
               default { pool default_pool }
        }
    }
    

    Cheers, Kai

  • That worked! Thanks!

     

    One thing I wondered. What does the "--" after switch -glob do?