Forum Discussion
Viv_Richards
Oct 01, 2024Cirrostratus
Need to change HTML tag in HTTP response
Dear Team,
If anybody need to change HTML tag or something similar to below in HTTP Response, you can refer it.
For example, I would like to change "name" with "XYZ" in HTTP response, you can use below iRule
=====================
when HTTP_REQUEST {
#To avoid HTTP/1.0 to chunked encoding and to prevent compression remove Accept-Encoding
HTTP::version 1.0
HTTP::header remove Accept-Encoding
}
when HTTP_RESPONSE {
#Before collecting HTTP response, check whether content type is HTML or not
if {[HTTP::header Content-Type] contains "text/html"} {
# Collect up to 1MB of the response body
HTTP::collect [expr 1024*1024]
}
}
when HTTP_RESPONSE_DATA {
#Ensure it is HTML Content
if {[HTTP::header Content-Type] contains "text/html"} {
# First replacement: replace "name=" with "XYZ="
set find "name="
set replace "XYZ="
set new_response [HTTP::payload]
#Replace payload
if {[regsub -all $find $new_response $replace new_response] > 0} {
HTTP::payload replace 0 [HTTP::payload length] $new_response
}
}
}
=========================
Hi,
Using a Stream profile will be better for performance.
https://my.f5.com/manage/s/article/K39394712
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