Forum Discussion
Daniel_Frye_222
Nimbostratus
Jul 14, 2005Rewrite host with an iRule?
Hello, hopefully someone knows the answer to this. I'm trying to find a way with an iRule (or any functionality really) to take a url like https://apple.fruit.com/application/xyz.html and convert it t...
Jul 15, 2005
You aren't stuck. You can do something like the following:
when HTTP_REQUEST {
Don't allow data to be chunked so we can correctly
replace payload below
if { [HTTP::version] eq "1.1" } {
if { [HTTP::header is_keepalive] } {
HTTP::header replace "Connection" "Keep-Alive"
}
HTTP::version "1.0"
}
change host header
if { [HTTP::host] eq "apple.fruit.com" } {
HTTP::header replace "Host" "peanut.bean.com"
}
}
when HTTP_RESPONSE {
collect response data
if { [HTTP::header exists "Content-Length"] } {
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 4294967295
}
if { $content_length > 0 } {
HTTP::collect $content_length
}
}
when HTTP_RESPONSE_DATA {
set find "peanut.bean.com"
set replace "apple.fruit.com"
set offset 0
set diff [expr [string length $replace] - [string length $find]]
Get indices of all instances of find string in the payload
set indices [regexp -all -inline -indices $find [HTTP::payload]]
foreach idx $indices {
set start [expr [lindex $idx 0] + $offset]
set end [expr [lindex $idx 1] + $offset]
set len [expr {$end - $start + 1}]
replace the instance of find with the contents of replace
HTTP::payload replace $start $len $replace
modify offset if the replace string is larger or smaller
than find.
incr offset $diff
}
}In the HTTP_REQUEST event, I've used the HTTP::header replace command to replace the host header. and in the HTTP_RESPONSE_DATA event, I've used a regexp call to return all start,end pairs of the peanut.bean.com string and replaced it with apple.fruit.com.
Good luck!
-Joe
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