Technical Forum
Ask questions. Discover Answers.
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

iRule Checking for No Value

BunnyJunJun
Altostratus
Altostratus

Hi All,

Just want to check with the fellow community members if you all have any idea on how to use iRules to check for no value?

Basically, I am crafting an iRule that search for all headers and sieving out that it starts with sec-ch. If it starts with sec-ch and there isn't any value (tried playing around and this is not an empty string), how do i use iRules to check it as an if condition?

if {$header_name eq ????}, where ???? represents no value. Do assist if possible and share your experiences πŸ˜„ 

2 ACCEPTED SOLUTIONS

Not sure I completely understand. the sec-ch-mobile header has no value and is not an empty string? I don't think it can be both of these. Try logging what the value actually is:

when HTTP_REQUEST {
    foreach x [string tolower [HTTP::header names]] {
        if { $x starts_with "sec-ch" } {
            log local0. "header($x) == |[HTTP::header $x]|"
        }
    }
}

I put the pipes in there to show if there's actually just white space. Still technically a non-empty string, not equal to "".

View solution in original post

local0. goes to the LTM log:

tail -f /var/log/ltm

View solution in original post

7 REPLIES 7

Kevin_Stewart
F5 Employee
F5 Employee

Something like this maybe:

when HTTP_REQUEST {
    foreach x [string tolower [HTTP::header names]] {
        if { ( $x starts_with "sec-ch" ) and ( [HTTP::header $x] eq "" ) } {
            log local0. "found empty sec-ch header"
        }
    }
}

Hi Kevin,

Thanks! I did roughly the same, however, in your context, x has no value. It is not even a string. Hence, quite hard for me to further "manipulate" x.

I was thinking to concatenate it like those we do for typical coding. (i.e. var temp = "" + x, and temp will be a string with x valueless). Is this possible in terms of iRules?

x is the header name. Are you saying the header doesn't exist?

Hi Kevin,

Header exist. An example of the request captured would be as such.

Header A: valueA
Header B: valueB
sec-ch-mobile: 
Header C: valueC

Given the idea of above, sec-ch-mobile has no value and it is not an empty string. As such, how do i check for x is an empty value given your sample iRules above?

Not sure I completely understand. the sec-ch-mobile header has no value and is not an empty string? I don't think it can be both of these. Try logging what the value actually is:

when HTTP_REQUEST {
    foreach x [string tolower [HTTP::header names]] {
        if { $x starts_with "sec-ch" } {
            log local0. "header($x) == |[HTTP::header $x]|"
        }
    }
}

I put the pipes in there to show if there's actually just white space. Still technically a non-empty string, not equal to "".

Hi Kevin, any idea how do i access the logs? I am accessing via putty and when i am in the tmsh, i tried to quit tmsh and the whole command prompt just closes.. 😞

local0. goes to the LTM log:

tail -f /var/log/ltm