27-Sep-2022 07:43
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 😄
Solved! Go to Solution.
28-Sep-2022 03:40
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 "".
27-Oct-2022 05:12
27-Sep-2022 09:24
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"
}
}
}
27-Sep-2022 09:32
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?
27-Sep-2022 10:03
x is the header name. Are you saying the header doesn't exist?
27-Sep-2022 18:30
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?
28-Sep-2022 03:40
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 "".
27-Oct-2022 03:41
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.. 😞
27-Oct-2022 05:12
local0. goes to the LTM log:
tail -f /var/log/ltm