Forum Discussion
Charlie_2_10323
Nimbostratus
May 15, 2009HTTP Respond Data replacing ?
Hi
I will rewrite response hostname.
HTTP_Response function well, but HTTP_Respond_Data not.
We have on Request and Respond site HTTPS access
Client is ter...
hoolio
Cirrostratus
May 18, 2009It would be more efficient to use a stream profile and iRule to rewrite the response content compared with collecting the response payload. Here is a generic (untested) example. You could add your request URI rewriting logic to it.
Aaron
LTM configuration object requirements:
- The virtual server must have an HTTP profile configured
- The virtual server must have a blank STREAM profile configured
- The virtual server must have a default pool configured
iRule configuration requirements:
- Debug can be enabled/disabled in the RULE_INIT event by setting ::rewrite_debug to 1 or 0 respectively.
- Outside the RULE_INIT section, no other changes should need to be made.
when RULE_INIT {
Log debug messages to /var/log/ltm? 1=yes, 0=no
set ::rewrite_debug 1
String to find in response headers and/or data
set ::find "oldname.example.com"
String to replace in response headers and/or data
set ::replace "newname.example.com"
}
when HTTP_REQUEST {
if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host][HTTP::uri]"}
HTTP::header remove "Accept-Encoding"
if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Removing Accept-Encoding request header"}
}
when HTTP_RESPONSE {
Rewrite Location header value in HTTP redirects if it contains the $::find string
if {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $::find}{
Replace $::find with $::replace in Location header value
HTTP::header replace Location [string map "$::find $::replace" [HTTP::header replace Location]]
if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Updated location from [HTTP::header replace Location]\
to [string map "$::find $::replace" [HTTP::header replace Location]]"}
}
Rewrite the response body if the response type is text
if { [HTTP::header "Content-Type"] starts_with "text/" } {
Configure the find/replace strings
STREAM::expression "@$::find@$::replace@"
Enable the stream filter
STREAM::enable
if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Enabled stream filter for $::find -> $::replace"}
} else {
Disable the stream filter for non-text responses
STREAM::disable
}
}
}
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