Forum Discussion
smp_86112
Cirrostratus
Jun 24, 2010Optimizing If statement conditions
I see this examples like this all over the place:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.myhost.com" and [HTTP::uri] equals "/myuri" } {
HTTP::redirect https://[HTTP::host][HTTP::...
hoolio
Cirrostratus
Jun 28, 2010I think that's just down to the extra few cycles it takes to handle a longer string that's being set to lower case:
% set str ABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMN...
% string length $str
1000
% time {string tolower $str} 1000
79 microseconds per iteration
% set smaller_str [string range $str 100 end]
% time {string tolower $smaller_str} 1000
65 microseconds per iteration/
Though in theory you should set the Host value to lower case in order to check it. RFC2616 states that the Host evaluation must be done case-insensitively. In practice, I think all major browsers set the host to lowercase before sending the request anyhow.
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects