Forum Discussion
ouch_32572
Nimbostratus
Mar 19, 2009irule to rewrite steam in request
Hi All,
I have an issue that i have manged to resolve on another Lb (zxtm)
I need help translating my rule into an irule for f5.
how do i rewite the stream on an incomming requ...
hoolio
Cirrostratus
Apr 14, 2009I don't think the regsub command is corrupting the data due to a bug--I assume it's converting the content to a different encoding which is breaking the application. For the customer I was working with, using hex encoding of the find/replace strings worked well. Can you give this a try?
when RULE_INIT {
Log debug messages to /var/log/ltm? (0=none, 1=minimal, 2=verbose)
Verbose logging can use a lot of CPU/disk space, so use sparingly in production.
set ::rewrite_http_debug 2
Max collection size (in bytes)
As the line to rewrite is in the first few hundred bytes, this can be set to lower than the normal 1Mib.
set ::max_collect_size 100000
Find value (hex encoded with \x00 format)
https:// -> \x68\x74\x74\x70\x3a\x2f\x2f
set ::replace "\x68\x74\x74\x70\x3a\x2f\x2f"
Replace value (hex encoded with \x00 format)
http:// -> \x68\x74\x74\x70\x3a\x2f\x2f
set ::find "\x68\x74\x74\x70\x3a\x2f\x2f"
}
when HTTP_REQUEST {
if {$::rewrite_http_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]"}
Check for POST request with Content-Type of multipart/*
if {[HTTP::method] eq "POST" and [HTTP::header Content-Type] starts_with "multipart"}{
Trigger collection of data
if {([HTTP::header exists "Content-Length"]) && ([HTTP::header "Content-Length"] <= $::max_collect_size)}{
set content_length [HTTP::header "Content-Length"]
} else {
set content_length $::max_collect_size
}
if { [info exists content_length] } {
HTTP::collect $content_length
if {$::rewrite_http_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Collecting $content_length bytes"}
}
}
}
when HTTP_REQUEST_DATA {
Check if POST data contains the parameter name, "webLoc"
if {[string first "webLoc" [HTTP::payload]] ne -1}{
if {$::rewrite_http_debug > 1}{
log local0. "[IP::client_addr]:[TCP::client_port]: Found parameter name in payload"
}
Replace https:// with http:// (with search/replace strings hex-encoded to avoid encoding conversion)
HTTP::payload replace 0 [HTTP::payload length] [regsub -all $::find [HTTP::payload] $::replace]
}
}
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
