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 Comment Scrubbers listed in the devCentral, but none of them seem to work in v11 LTM.
Would someone mind giving me a few pointers on this?
Many thanks
Anthony
3 Replies
- nitass
Employee
i think i do not see command which is not usable in v11. is it regex issue or something else? would it be possible to post example html? so, someone may be able to help.
HTML comment scrubber using a stream profile
https://devcentral.f5.com/wiki/iRules.HTML-comment-scrubber.ashx - Anthony
Nimbostratus
Here is the code that I have in place. I believe its the regex that isn't working as nothing much happens after that.
I have also looked at the stream profile, but we already use stream profiles on some of the Virtual Servers that this will be applied to.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] } }
Many thanks
Ant - nitass
Employee
do 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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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