Forum Discussion

Octavio_Rocha_6's avatar
Octavio_Rocha_6
Icon for Nimbostratus rankNimbostratus
Jun 08, 2007

Remove HTML comments

Hi,

 

 

I'm new to irules and I need to remove any html comments present on the website html code.

 

 

Basically, I need to remove any line like this " " from the http response payload.

 

 

Any ideas?

 

 

 

thanks,

 

 

Octavio

5 Replies

  • In case you hadn't gotten to it yet, here's a bit of code that should get you rolling:

     

     

    when HTTP_REQUEST {
       Don't allow data to be chunked
      if { [HTTP::version] eq "1.1" } {
        if { [HTTP::header is_keepalive] } {
          HTTP::header replace "Connection" "Keep-Alive"
        }
         HTTP::version "1.0"
      }
    }
    when HTTP_RESPONSE {
      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
      }
    }
    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]
      }
    }

     

     

    I modified the SSN scrubber on CodeShare. If anyone sees any problems with the HTML Comment regex, please let me know!

     

     

    -Joe
  • Per the w3 note (Click here), you can't have white space between the

     

    Something like this comes close to matching the w3 definition of a comment:

     

     

  • Posted By hoolio on 06/11/2007 3:36 AM

     

     

    Per the w3 note (Click here), you can't have white space between the

     

    Something like this comes close to matching the w3 definition of a comment:

     

     

     

  • Cool. It doesn't get some odd ball cases like , but I think it should work for most situations.

     

     

    Aaron