Forum Discussion
Jukka_Vaisanen_
Nimbostratus
May 03, 2007Matching binary data with NULLs from HTTP post data
I need to be able to select a different pool if a HTTP POST contains a certain string. However the HTTP post data is completely arbitrary binary mush and in there I need to pick out a series of bytes followed by a string of ascii characters and terminated by a NULL (0x00).
My understanding is that TCL strings are semi-8-bit clean.. they can contain 8 bit characters but not NULLs. So what can I do in this case? Below is my first attempt which however doesn't seem to work (not surprised).
when HTTP_REQUEST {
if { [HTTP::method] == "POST" } {
HTTP::collect [HTTP::header Content-Length]
}
}
when HTTP_REQUEST_DATA {
if { [HTTP::payload] matches_regex "\x03\xB0(.*)\x00" } {
pool B_pool
} else {
pool A_pool
}
HTTP::release
}
- Sorry for the delay on the response, I've been trying to get my hand around binary parsing and how it works within the HTTP profile. What I'd recommend is that you use the TCL regexp command to do the regular expression as I'm not sure if the matches_regexp supports hex escaping the same way that regexp does.
when HTTP_REQUEST { if { [HTTP::method] == "POST" } { HTTP::collect [HTTP::header Content-Length] } } when HTTP_REQUEST_DATA { if { [regexp {\x03\xB0(.*)\x00} [HTTP::payload]] } { pool B_pool } else { pool A_pool } HTTP::release }
set f [binary format a4hHa3h lala 3 B0 abc 0] if { [regexp {\x03\xB0(.*)\x00} $f] { log local0. "found match!" }
- Jukka_Vaisanen_
Nimbostratus
Thanks for the tips Joe, I'll post my results here when I've got the test environment set up again. - Can't wait to hear if it works...
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