Rory_Hewitt_F5_
Sep 30, 2015Cirrus
Do I need to check HTTP::header exists before checking value?
I feel like this is a simple question, but I can't seem to find a definitive answer...
To check the value of a particular HTTP header, I can do this:
if { [HTTP::header Origin] ends_with "example.com" } {
...do stuff here...
}
My basic question is "What happens is the Origin header is not passed?"...
The spec says that HTTP::header will return null if the header called does not exist. What does this mean for my if statement - is null treated the same as false in an if statement?
If the above code example will be problematic if Origin is not passed, can I write the code as a single line, like this:
if { [HTTP::header exists Origin] and [HTTP::header Origin] ends_with "example.com" } {
...do stuff here...
}
or does it need to be two separate nested if statements:
if { [HTTP::header exists Origin] } {
if {[HTTP::header Origin] ends_with "example.com" } {
...do stuff here...
}
}