Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral


Questions and Answers

Loading... Loading...

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 Answer(s):

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
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 {<![ \r\n\t]*--([^\-]|[\r\n]|-[^\-])*[^/][^/]--[ \r\n\t]*>} [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
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 {<![\r\n\t]*--([^\-]|[\r\n]|-[^\-])*[^/][^/]--[\r\n\t]*>} [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

<html>
<head></head>
<body>
<!--
this is comment line
-->
This is 101 host.
<br><br><img src="f5.gif">
</body>
</html>

# 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

<html>
<head></head>
<body>

This is 101 host.
<br><br><img src="f5.gif">
</body>
</html>

Your answer:

You must be logged in to reply. You can login here.