Forum Discussion
johns
Employee
Mar 02, 2006iRule recognize blank space in URI?
Hi, I need to detect blank space in URI and either remove it or rewrite it:
www.mysite.com/some content/showme.html
to
www.mysite.com/some%20content/showme.html
Current solution in place is only recognizing up to the space so it reads:
www.mysite.com/some. and breaks the client request to the server.
I am thinking if I can find out how BIG-IP can detect the space, I will just replace it with characters that I need in its place.
Thanks.
- unRuleY_95363Historic F5 AccountIf the uri in the HTTP request contains a space, then that is actually an illegal request according to the HTTP RFC. This is because HTTP uses spaces to separate the method, uri, and version on the first line of the HTTP request. I'm assuming you are using some kind of homegrown client? To do this, you'll have to parse the request at the TCP layer using the CLIENT_DATA event and the TCP::payload commands. This is because our HTTP engine will only parse up to the space when parsing for the uri. You could try looking in the version to see if the rest of the uri ends up there (see HTTP::version).
- johns
Employee
So using TCP::payload command, I can do a "contains" to find the URI, but the URI is not the same all the time and I will need to find a way to find a URI with space in it? Is it possible to "match" on the space within the URI? - unRuleY_95363Historic F5 AccountYou may want to use a regular expression and bound it by the method and the version and/or newline. Maybe something like:
/^GET .+ (HTTP/.+)?\r?\n/
- johns
Employee
I just started testing this and interestingly enough, BIG-IP is replacing space within URI with %20, when I looked at the tcpdump, as well iRule log statement. - johns
Employee
So, once you find the match, how do you extract that portion into a variable? - johns
Employee
I used - "[TCP::payload] matches_regex "/vMoD.+Y" is a boolean comparison. It's outcome of 0 or 1 is not a command and can't be enclosed in brackets (which indicate execution of a command). If you want to extract the content, then you will have to use one of the builtin regular expression commands like regexp (Click here).
when CLIENT_DATA { regexp returns 1 if a match is found if { [regexp "/vMoD.+Y" [TCP::payload] match] } log local0. "match found: $match" } else { log local0. "no match" } }
- johns
Employee
Thank you, I was able to extract the URI b/w "GET" and " HTTP" (to remove the last space before HTTP) with: - johns
Employee
I am also trying to see if I can use HTTP::collect to access HTTP::request or HTTP::payload, but HTTP::request generates "undefined procedure" and the payload comes up empty..... oh, and HTTP::decode is not supported? - johns
Employee
With a lot of help, I am down to the rule below. But the URI is coming out with leading "{" from "regexp -inline... "(I think) and I tried using string trimright to the result with "\}" as the character, but still can't remove that last brace. Any ideas?
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