stream
3 TopicsRemove Whitespace from HTTP Response Payload
Problem this snippet solves: Summary: Strip extraneous white space from HTML in the HTTP response payload Here is a simple iRule which uses a stream filter and STREAM::expression based iRule to two or more consecutive whitespace characters with a space. It hasn't been tested in production so try it on a test virtual server or test unit first! Code : when HTTP_REQUEST { # Prevent server compression HTTP::header remove "Accept-Encoding" # Disable the stream filter by default STREAM::disable } when HTTP_RESPONSE { # Check if server response is text based if { [HTTP::header Content-Type] contains "text" }{ # Set the stream expression to match two or more consecutive whitespace characters # Replace them with a single space STREAM::expression @\s+@ @} STREAM::enable } }546Views0likes1CommentHTML Comment Scrubber with Stream Profile
Problem this snippet solves: This example uses similar logic to scrub out HTML comments as the Html Comment Scrubber rule. Instead of collecting the HTTP response payloads, it uses the stream filter to replace the strings inline. This should be more efficient than buffering the entire payload with the HTTP::collect command. How to use this snippet: The iRule requires a blank stream profile and a custom HTTP profile with Chunking set to Rechunk if you change the response content length. Code : when HTTP_REQUEST { # Prevent the server from sending chunked response data if { [HTTP::version] eq "1.1" } { # Force downgrade to HTTP 1.0, but still allow keep-alive connections. # Since HTTP 1.1 is keep-alive by default, and 1.0 is not, # we need make sure the headers reflect the keep-alive status. if { [HTTP::header is_keepalive] } { HTTP::header replace "Connection" "Keep-Alive" } } # Disable the stream filter by default STREAM::disable } when HTTP_RESPONSE { # Check if the response is HTML if {[HTTP::header "Content-Type"] contains html{ # Set the stream expression to match HTML comments and replace them with nothing STREAM::expression {###} STREAM::enable } } # STREAM_MATCHED is triggered when the stream filter find string is found when STREAM_MATCHED { # Log the string which matched the stream profile log local0. "[IP::client_addr]:[TCP::client_port]: Removed comment: [STREAM::match]" } Tested this on version: 10.0412Views0likes0CommentsiRule to count individual STREAM::expression hits
Problem this snippet solves: Hi Folks, the provided iRule below can be used to count and analyse individual STREAM::expression hits. Imagine you have some more of less interesting HTML content that needs several content rewrites... "On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look." -MSOffice ... and you apply a STREAM::expression with lots of individual translations to it... STREAM::expression @a@A@@b@B@@c@C@@d@D@@e@E@@f@F@@g@G@@h@H@@i@I@@j@J@@k@K@@l@L@@m@M@@n@N@@o@O@@p@P@@q@Q@@r@R@@s@S@@t@T@@u@U@@v@V@@w@W@@x@X@@y@Y@@z@Z@ ... then you could use the iRule below to [log] which individual expression has been triggered how many times on which ressource. Thu Sep 8 16:07:43 CEST 2016 debug f5-02 tmm[16579] STREAM hits on URL /stream: 271 ( Pattern:p = 2 | ( Pattern:a = 18 | ( Pattern:r = 21 | ( Pattern:b = 4 | ( Pattern:c = 13 | ( Pattern:s = 19 | ( Pattern:d = 12 | ( Pattern:t = 28 | ( Pattern:u = 12 | ( Pattern:e = 36 | ( Pattern:f = 2 | ( Pattern:v = 2 | ( Pattern:w = 2 | ( Pattern:g = 6 | ( Pattern:h = 12 | ( Pattern:y = 4 | ( Pattern:i = 15 | ( Pattern:k = 3 | ( Pattern:l = 14 | ( Pattern:m = 5 | ( Pattern:n = 15 | ( Pattern:o = 26 ) Cheers, Kai How to use this snippet: Attach the provided iRule to your Virtual Server which performs [STREAM] operations Request the streamed content as usual. Take a look to your LTM logfile. Code : when STREAM_MATCHED { set stream_result(path) $http_path if { [info exists stream_result(Pattern:[STREAM::match])] } then { incr stream_result(Pattern:[STREAM::match]) } else { set stream_result(Pattern:[STREAM::match]) 1 } } when HTTP_REQUEST { set http_path [HTTP::path] if { [info exists stream_result(path)] } then { set stream_result(match_total) 0 foreach stream_result(pattern) [array names stream_result Pattern:*] { incr stream_result(match_total) $stream_result($stream_result(pattern)) append stream_result(match_detailed) "( $stream_result(pattern) = $stream_result($stream_result(pattern)) | " } log -noname local0.debug "STREAM hits on URL $stream_result(path): $stream_result(match_total) [string trimright $stream_result(match_detailed) " |"] )" unset -nocomplain stream_result } } when CLIENT_CLOSED { if { [info exists stream_result(path)] } then { set stream_result(match_total) 0 foreach stream_result(pattern) [array names stream_result Pattern:*] { incr stream_result(match_total) $stream_result($stream_result(pattern)) append stream_result(match_detailed) "( $stream_result(pattern) = $stream_result($stream_result(pattern)) | " } log -noname local0.debug "STREAM hits on URL $stream_result(path): $stream_result(match_total) [string trimright $stream_result(match_detailed) " |"] )" unset -nocomplain stream_result } } Tested this on version: 12.0225Views0likes0Comments