Forum Discussion
irule class match each query param separately
Your use case might extend to three parameters as in if it extends it will always have three or as in a request may have two or may have three?
If you want to pull out individual parameters and re-order them you can extract with URI::query. Unlike HTTP::query it doesn't pull from the existing request, you have to feed it a URI to extract the query from. It has two forms. The first simply extracts the query portion like HTTP::query (but could be used on a source other than the current request) and the second extracts a specific parameter. you would call it like this:
[URI::query [HTTP::uri] param1]
which would return "param1" from the above request.
You could use this to quickly re-order the values of the parameters.
set param1 "param1"
set param2 "param2"
set param1_segment = [URI::query [HTTP::uri] $param1]
set param2_segment = [URI::query [HTTP::uri] $param2]
Now the class command has a number of different ways you can call it. equals really only tells you that what you are looking for matches one of the entries in it. you can also add the -value flag to get the value of that option. I.E.
class match -value $param1_segment&$param2_segment equals dg1 wouldn't return true for "param1=p11¶m2=p21" it would return host1.
The upshot is you just construct a single lookup. put param1 and 2 together, if 3 exists add that one.
last bit is to avoid having to stuff all those various possible combinations together you simply stuff them together in the correct order. assign the results to what ever you're going to use it for (variable, pool selection, etc) and to avoid errors/have a fallback if it doesn't exist wrap the whole thing in a TCL catch statement
if { [catch {pool class match -value $param1_segment&$param2_segment equals dg1}] {
pool fallBackPool
}
The contents of the if statement will be executed only if the first pool assignment fails. which it would if there was no pool returned from the class match value.
EDIT: My first attempt to post a response failed so I had to retype it and forgot to add links URI::query https://devcentral.f5.com/wiki/iRules.URI__query.ashx
Recent Discussions
Related Content
* 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