Forum Discussion
mikey_webb
Cirrus
Jan 07, 2015Help with pattern match irule required
Need help with an irule to drop the request if pattern is not matched. The link and pattern is always as below whereby only the values will change....such as vid, height, quality values etc
htt...
Michael_Jenkins
Cirrostratus
Jan 07, 2015Tested this with
tclsh through the CLI with success. You could use the tcl string match command to build your filter
Good A: Proper pattern
set goodA "/getimage.aspx?vid=84687usehttp=0&cat=default&class=books&size=custom&resize=1&dpi=300&quality=90&type=jpg&width=&height=&id=470746"
Bad A: Removed vid parameter
set badA "/getimage.aspx?usehttp=0&cat=default&class=books&size=custom&resize=1&dpi=300&quality=90&type=jpg&width=&height=&id=470746"
Good B: Proper pattern
set goodB "/getimage.aspx?vid=8461&usehttp=0&cat=default&class=books&size=custom&resize=1&dpi=300&quality=100&type=jpg&width=&height=&id=470784"
Bad B: Swapped parameter location (usehttp & vid)
set badB "/getimage.aspx?usehttp=0&vid=8461&cat=default&class=books&size=custom&resize=1&dpi=300&quality=100&type=jpg&width=&height=&id=470784"
Match pattern
set pattern "/getimage.aspx\?vid=*usehttp=?&cat=*&class=*&size=*&resize=?&dpi=*&quality=*&type=*&width=*&height=*&id=*"
echo "A (Good): [string match $pattern $goodA]"
echo "A (Bad) : [string match $pattern $badA]"
echo "B (Good): [string match $pattern $goodB]"
echo "B (Bad) : [string match $pattern $badB]"
so an iRule might look like this
when HTTP_REQUEST {
You don't have to set the pattern to a variable. you could just as easily paste it in the string match command, but this is a little clean (though not as performant)
set pattern "/getimage.aspx\?vid=*usehttp=?&cat=*&class=*&size=*&resize=?&dpi=*&quality=*&type=*&width=*&height=*&id=*"
if { not ([string match $pattern [string tolower [HTTP::uri]]]) } {
Drop the request
drop
}
}
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