Forum Discussion
JRahm
Admin
Jan 22, 2026AppWorld DC Booth Kiosk Generator
Welcome to AppWorld, community! You may or may not be with us in person, but you can watch this thread for iRules that are either generated or described by the Distributed Cloud AI Assistant.
JimmyPackets
Cirrus
Mar 11, 2026AI-Generated iRule
Prompt: Inject a JavaScript analytics snippet into HTML response bodies before the closing </body> tag
Generated iRule (by F5 Distributed Cloud AI Assistant):
when HTTP_RESPONSE priority 500 {
# Check if Content-Type header exists and contains "text/html"
if { [HTTP::header exists "Content-Type"] && [string tolower [HTTP::header "Content-Type"]] contains "text/html" } {
# Get Content-Length header value if present, else set to 0
if { [HTTP::header exists "Content-Length"] } {
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 0
}
# Collect the entire response body based on Content-Length or up to 1MB if unknown or large
if { $content_length > 0 && $content_length < 1048576 } {
HTTP::collect $content_length
} else {
HTTP::collect 1048576
}
}
}
when HTTP_RESPONSE_DATA priority 500 {
# Define the JavaScript analytics snippet to inject
set js_snippet "<script>/* Analytics snippet here */</script>"
# Get the full response body payload
set content [HTTP::payload]
# Search for the closing </body> tag case-insensitively
if {[regexp -nocase -- {</body>} $content match body_tag_start]} {
# Insert the JavaScript snippet before the closing </body> tag
regsub -nocase -- {</body>} $content "${js_snippet}</body>" new_content
} else {
# If no </body> tag found, append the snippet at the end
append content $js_snippet
set new_content $content
}
# Replace the payload with the modified content
HTTP::payload replace 0 [HTTP::payload length] $new_content
# Update the Content-Length header to the new payload length
HTTP::header replace "Content-Length" [string length $new_content]
# Release the modified payload to continue processing
HTTP::release
}
F5, Inc. ("F5") disclaims all liability in connection with any output generated by the AI Assistant ("Output") or use thereof, including without limitation any negative business impact caused by your use of Output to administer, direct, configure or control the operation and functioning of any F5 products. Output is provided "as is" without any warranties of any kind.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