Forum Discussion
Anthony
Nimbostratus
Jan 17, 2013Removing whitespace and HTML comments
Hi all,
I've been tasked with the job of creating an iRule to remove the white space and HTML comments from our web pages.
I have tried using the various examples of HTML Com...
nitass
Employee
Jan 17, 2013do you have example html which is not working?
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
destination 172.28.20.14:80
ip-protocol tcp
mask 255.255.255.255
pool foo
profiles {
http { }
tcp { }
}
rules {
myrule
}
source 0.0.0.0/0
source-address-translation {
type automap
}
vlans-disabled
}
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
members {
200.200.200.101:80 {
address 200.200.200.101
}
}
}
root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm rule myrule
ltm rule myrule {
when HTTP_REQUEST {
if { [HTTP::version] eq "1.1" } {
if { [HTTP::header is_keepalive] } {
HTTP::header replace "Connection" "Keep-Alive"
}
HTTP::version "1.0"
log local0. "HTTP version reset to 1.0"
}
}
when HTTP_RESPONSE {
Ensure all of the HTTP response is collected
if { [HTTP::header exists "Content-Length"] } {
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 1000000
}
if { $content_length > 0 } {
HTTP::collect $content_length
log local0. "Content-Length: $content_length"
}
}
when HTTP_RESPONSE_DATA {
Find the HTML comments
set indices [regexp -all -inline -indices {} [HTTP::payload]]
Replace the comments with spaces in the response
log local0. "Indices: $indices"
foreach idx $indices {
set start [lindex $idx 0]
set len [expr {[lindex $idx 1] - $start + 1}]
log local0. "Start: $start, Len: $len"
HTTP::payload replace $start $len [string repeat " " $len]
}
}
}
original response
[root@ve11a:Active:Changes Pending] config curl -i http://200.200.200.101/foo.html
HTTP/1.1 200 OK
Date: Thu, 17 Jan 2013 13:37:31 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Thu, 17 Jan 2013 13:30:53 GMT
ETag: "418483-77-ff9d40"
Accept-Ranges: bytes
Content-Length: 119
Content-Type: text/html; charset=UTF-8
This is 101 host.
modified response
[root@ve11a:Active:Changes Pending] config curl -i http://172.28.20.14/foo.html
HTTP/1.1 200 OK
Date: Thu, 17 Jan 2013 13:37:46 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Thu, 17 Jan 2013 13:30:53 GMT
ETag: "418483-77-ff9d40"
Accept-Ranges: bytes
Content-Length: 119
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
This is 101 host.
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