Forum Discussion
Thornid
Nimbostratus
Sep 13, 2019Modify HTTP Payload in Response Question
Hello all
We have a requirement to modify the <HEAD> HTML tag in responses for a specific URL. I've been looking around trying to piece bits together but not having too much luck in the lab.
My understanding is to use the HTTP::collect to collect response data then access that data via the HTTP::payload command. I found an example online which I have attempt to butcher with no luck, as below. Hoping for some guidance.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/home"}{
continue }
}
when HTTP_RESPONSE {
HTTP::collect [expr 1024*1024]
}
when HTTP_RESPONSE_DATA {
set find "<HEAD>"
set replace "<HEAD> SOME_OTHER_DATA"
if {[ regsub -all $find [HTTP::payload] $replace new_response] > 0} {
HTTP::payload replace 0 [HTTP::payload length] $new_response
}
}
Thank you.
1 Reply
Sort By
- youssef1
Cumulonimbus
Hi,
You can use my example with stream profile.
or modify your irule with the following code:
when HTTP_RESPONSE_DATA { set find "<HEAD>" set replace "<HEAD> SOME_OTHER_DATA" if {[ regsub -all $find [HTTP::payload] $replace new_response] > 0} { regsub -all $find [HTTP::payload] $replace newdata log "Replacing payload with new data." HTTP::payload replace 0 [HTTP::payload length] $newdata HTTP::release } }
regards
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