Forum Discussion
jrok_47156
Nimbostratus
Aug 30, 2012HTTP::uri equality question
This may be a very simple question but I have looked for a few hours now and cannot find a good answer.
Why does this work?
switch [HTTP::uri] {
"/maintenance" {
Send an HTTP 200 response with a Javascript meta-refresh
HTTP::respond 200 content \
"
But this throws an SSL connection reset?
if { [HTTP::uri] == "/maintenance" }
{
HTTP::respond 200 content \
"
I also tried "equals" but to no avail. Does HTTP::uri have special if {} rules that only allow "starts_with", "contains", etc.?
3 Replies
- Michael_Yates
Nimbostratus
Hi jrok,
The switch statment is a literal string compare. Pretty much the same as "equals".
The "==" is an absolute comparison which is normally reserved for number value comparisons and in your case it has to convert the "/maintenance" to a string since it is not a number and then perform a string compare (extra work and less efficient).
I have no idea why you would be getting an SSL connection reset. I've never seen that problem before in a compare like this, but to answer your other question, yes, there are other comparisons that you can do within an if statement.
starts_with
ends_with
contains
equals
Hope this helps. - jrok_47156
Nimbostratus
Hey thanks Michael.
I had re-purposed an older more complicated iRule for a new site and removed the switch and just made it an if. It took awhile to figure out what was causing the connection error but it was the if. If I put back the switch it works perfectly. We also thought the == might be the problem so we tried equals too.
Should this work?
if { [HTTP::uri] equals "/maintenance" }
We can certainly use the switch with only a single comparison but it seems like the if should work too. - Michael_Yates
Nimbostratus
Yes, that will work, but it's an absolute search.
So if somone went to http://www.website.com/maintenance/index.html or anything after "/maintenance" the iRule would not work.
I would suggest using "starts_with" so that it would basically be http://www.website.com/maintenance(anyting you could possibly put after it to qualify for this action).
Strange that you had to remove the switch statement. In a switch statement you have to enabe the "-glob" in order to use Wildcards to basically compensate for not having the starts_with or ends_with options.
switch -glob [ string tolower [HTTP::uri]] {
"*/maintenance" { action } <- Compensates for "starts_with"
"/maintenance*" { action } <- Compensates for "ends_with"
Hope this helps.
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