Forum Discussion
James_Wrubel_48
Nimbostratus
Jul 03, 2009regexp to parse querystring parameters
I am trying to get a list of querystring parameters from the URI. There's an example iRule that does this here:
http://devcentral.f5.com/wiki/default.aspx/iRules/URIInterrogation.html
The relevant code is:
set namevals [split [HTTP::query] "&"]
for {set i 0} {$i < [llength $namevals]} {incr i} {
set params [split [lindex $namevals $i] "="]
set pnum [expr $i+1]
log local0. "Param\[$pnum\]: [lindex $params 0]"
log local0. "Value\[$pnum\]: [URI::query [HTTP::uri] [lindex $params 0]]"
}
}
That code works fine, but it seems like this would be more efficient as a regexp, or even a foreach. Can anyone think of a better way to implement this?
- hoolio
Cirrostratus
I'd think this looping with string commands would be more efficient than a regex. A foreach loop would probably be about the same. You could test these options using the timing command (Click here). - James_Wrubel_48
Nimbostratus
Makes sense. This is related to my other post - I'm stuck in the TCP stream without an HTTP profile since I am tunneling non HTTP traffic over HTTP, so I'm forced to do all my HTTP parsing manually (joy of joys). - hoolio
Cirrostratus
If you have any string in the format of ?name1=value1&name2=value2, you can use URI::query to parse the value of any of the parameters:
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