Forum Discussion
Richard_Marsha1
Nimbostratus
Sep 06, 2006http content rewrite
Hi,
I'm looking for some help writing my first iRule.
We are quering a remote domain for an xml feed, but often the returned content begins with garbage - please see example below:
--------------------------------------------------------------------------------------
bless( do{\(my $o = 136523848)}, 'Cache::FastMmap::CImpl' )
5|87238978
$HashPage-->18<--
$HashSlot-->142389272<--
..............
undef
$Flags-->0<--
$Found-->0<--
Cache::FastMmap.pm************************
etc, etc....
--------------------------------------------------------------------------------------
what I need to do is remove everything before the xml opening tags and leave the rest as it is. i only want this iRule to apply when we are talking to a particular domain to save on load - we do similar queries against a number of domains, but only one has the issue.
i have seen the iRule that strips a CC number from the content and understand parts of it, but don't get how I can modify it for my purposes. Can someone point me in the right direction, or offer some suggestions on how i can do this?
Thanks
Rich
6 Replies
- bl0ndie_127134Historic F5 AccountWow, I am surprised no one jumped on this one. You should be able to do this using the new stream profile introduced in version 9.2. Check out this post for more details. Good luck!
Click here - Richard_Marsha1
Nimbostratus
Hey, thanks for the reply. unfortunatly we're running 9.0 and 9.1 - f5 support hgave advised against running 9.2 yet. Can we still do something in these versions? - Deb_Allen_18Historic F5 AccountMaybe something like this:
Create a class of type string containing the hostnames for which you want the rule to run:class BadServers { "www.domain1.com" "www.domain2.com" }
to be used by this iRule:rule rewrite_content { when HTTP_REQUEST { if {[matchclass [HTTP::host] $::BadServers]}{ set replace 1 } when HTTP_RESPONSE { if {$replace}{ if {[HTTP::header exists Content-Length]}{ set clen [HTTP::header Content-Length] } else { set clen 4294967295 } if { $clength > 0 } { HTTP::collect $clen } } } when HTTP_RESPONSE_DATA { if {$replace}{ find beginning of data to keep set xml_start [string first { if { $xml_start > 0 }{ set newPayload [string range [HTTP::payload] $xml_start end] HTTP::payload replace 0 $clen $newPayload } HTTP::release } } }
HTH
/deb - Richard_Marsha1
Nimbostratus
Hey Deb,
Thanks for the suggestion - I will take a look at it and see what I can understand (and apply to our problem)
Regards
Rich - Richard_Marsha1
Nimbostratus
Well,
I've finally managed to get the thing to compile, but I'm not currently able to test it (because it's production traffic) but i guess it should work.
Here's the irule: where BadServers = foo.bar.com
when HTTP_REQUEST {
if { [matchclass [HTTP::host] equals $::BadServers] }{
set replace 1
}
}
when HTTP_RESPONSE {
if {$replace > 0}{
if {[HTTP::header exists "Content-Length"]}{
set clen [HTTP::header "Content-Length"]
} else {
set clen 4294967295
}
if { $clen > 0 } {
HTTP::collect $clen
}
}
}
when HTTP_RESPONSE_DATA {
if {$replace}{
find beginning of data to keep
set xml_start [string first { if { $xml_start > 0 }{
set newPayload [string range [HTTP::payload] $xml_start end]
HTTP::payload replace 0 $clen $newPayload
}
HTTP::release
Log Results
log local0. "Found $xml_start replaced with $newPayload"
}
} - I would set replace to 0 as a default in the HTTP_REQUEST event or you will get a undefined variable error when trying to access it in the other events.
when HTTP_REQUEST { set replace 0 if { [matchclass [HTTP::host] equals $::BadServers] }{ set replace 1 } }
Otherwise, it looks good to me...
-Joe
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
