Forum Discussion
Mike_Perez_6161
Nimbostratus
Feb 18, 2010Parse the first and second character in the path?
I know what I have got below is not parsing the second character but is sort of displaying the concept.
Can some please give me a hand in the simplest form?
when HTTP_REQUEST {
Parse the first character in the path
switch -glob [HTTP::path] {
"/[a-alA-AL]*" {
pool reward-uat5.123.com_AA2AL
}
"/[am-blAM-BL]*" {
pool reward-uat5.123.com_AM2BL
}
"/[bm-cdBM-CD]*" {
pool reward-uat5.123.com_BM2CD
}
default {
Requested URI was a leading forward slash only
pool reward-uat5.123.com_AA2AL
}
}
}
3 Replies
- hoolio
Cirrostratus
Hi Mike,
You can check two characters using two character classes like this: [aA][bB]. This would match ab, Ab, aB and BB. AA2AL would be simple if you set the path to lower case ([string tolower [HTTP::path]]) and then used /a[a-l]*. However, I can't think of a simple way to handle two character ranges like am - bl.
Anyone have ideas on this?
Aaron - Mike_Perez_6161
Nimbostratus
Aaron,
Thanks a bunch for the idea here. It really got my wheels spinning. Got it to work with lowercase only at first. So basically repeated it with uppercase a the first letter to parse. Also the issue with it character ranging within the string was a huge road block. Was addressed by creating another query by going to the next character and still pointing it to the correct pool. A little more work but gets the job done. Aaron thanks again.
example will explain what I am talking about above.
when HTTP_REQUEST {
Parse the first then second character in the path
switch -glob [HTTP::path] {
"/a[a-lA-L]*" {
pool reward-uat5.123.com_AA2AL
}
"/A[a-lA-L]*" {
pool reward-uat5.123.com_AA2AL
}
"/a[m-zM-Z]*" {
pool reward-uat5.123.com_AM2BL
}
"/A[m-zM-Z]*" {
pool reward-uat5.123.com_AM2BL
}
"/b[a-lA-L]*" {
pool reward-uat5.123.com_AM2BL
}
"/B[a-lA-L]*" {
pool reward-uat5.123.com_AM2BL
}
"/b[m-zM-Z]*" {
pool reward-uat5.123.com_BM2CD
}
"/B[m-zM-Z]*" {
pool reward-uat5.123.com_BM2CD
}
"/c[a-dA-D]*" {
pool reward-uat5.123.com_BM2CD
}
"/C[a-dA-D]*" {
pool reward-uat5.123.com_BM2CD
}
default {
Requested URI was a leading forward slash only
pool reward-uat5.123.com_AA2AL
}
}
} - hoolio
Cirrostratus
That's a novel solution! You can logically set the path to lower case without modifying the actual path that in the request sent to the pool. This allows you to remove some switch cases. You can also combine multiple cases where the action is the same:when HTTP_REQUEST { Parse the first then second character in the path switch -glob [string tolower [HTTP::path]] { "/a[a-l]*" { pool reward-uat5.123.com_AA2AL } "/a[m-z]*" - "/b[a-l]*" { pool reward-uat5.123.com_AM2BL } "/b[m-z]*" - "/c[a-d]*" { pool reward-uat5.123.com_BM2CD } default { Requested URI was a leading forward slash only pool reward-uat5.123.com_AA2AL } } }
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
