Forum Discussion

keefyweefy's avatar
keefyweefy
Icon for Nimbostratus rankNimbostratus
Mar 24, 2011

simple stream replace not working

Hi Guys,

 

 

I'm trying to replace text within webpages but things arn't going to plan! As a result i've stripped this to be as simple as possible but still no joy. I've tried doing this two ways:

 

 

I've created a stream profile with source: Hello, target: 12345. Applied this to the VS. Then connected to a page which consists of: Hello - The text doesn't get replaced.

 

 

 

I've also tried creating and applying blank stream profile, ammending the assigned http profile to 'rechunk', and creating and applying the following iRule:

 

 

when HTTP_RESPONSE {

 

STREAM::expression "@Hello@45678@"

 

STREAM::enable

 

}

 

 

But the text still isn't getting replaced, any ideas?

 

 

Thanks

 

5 Replies

  • Hi Keith,

     

     

    The most common reason for replacements not being made is that the server is sending compressed data. Can you use a browser plugin like Fiddler2 or HttpFox to check for this? If so, you can either disable this option on the server, or add code to your iRule to prevent compression from being used. The STREAM::expression wiki page shows how to do this by removing the Accept-Encoding header:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/stream__expression

     

     

    Aaron
  • If you are going to use a Stream Profile in an iRule you need several things.

    1. A Blank Stream Profile (create a stream profile, name it, and save it with the options empty)

    
    profile stream blank.stream.profile {
       defaults from stream
    }
    

    2. An HTTP Profile (Suggest building a Custom Profile for using a Stream Profile with an iRule) that has "Response Chunking" set to "Rechunk"

    3. The iRule. This is also the way that you can "Overload" a Stream Profile to do multiple replacements (You can do it to a normal stream profile as well, but you have to totally do it command line).

    Base iRule:

    
    when HTTP_RESPONSE {
        STREAM::disable 
        STREAM::expression "@Hello@45678@ @Goodbye@12345@"
        STREAM::enable
        }
    }
    

    Need an exception to the Stream Profile? It requires two parts. HTTP_REQUEST sets the variable for the HTTP_RESPONSE to use:

    
    when HTTP_REQUEST {
        set uri [HTTP::uri] 
    }
    when HTTP_RESPONSE {
        STREAM::disable 
        STREAM::expression "@Hello@45678@ @Goodbye@12345@"
        if { !($uri contains "somefile.xml") || !($uri contains "/some/folder/") } {
           STREAM::enable
        }
    }
    
  • Previous Post of code was messed up:

     

     

    If you are going to use a Stream Profile in an iRule you need several things.

     

     

    1. A Blank Stream Profile (create a stream profile, name it, and save it with the options empty)

     

    2. An HTTP Profile (Suggest building a Custom Profile for using a Stream Profile with an iRule) that has "Response Chunking" set to "Rechunk"

     

    3. The iRule. This is also the way that you can "Overload" a Stream Profile to do multiple replacements (You can do it to a normal stream profile as well, but you have to totally do it command line).

     

     

    
    Stream Profile:
    -----------------------------------------------------------------
    profile stream blank.stream.profile {
       defaults from stream
    } 
    
    iRule 1:
    -----------------------------------------------------------------
    when HTTP_RESPONSE {
        STREAM::disable 
        STREAM::expression "@Hello@45678@ @Goodbye@12345@"
        STREAM::enable
        }
    }
    
    iRule 2:
    -----------------------------------------------------------------
    when HTTP_REQUEST {
        set uri [HTTP::uri] 
    }
    when HTTP_RESPONSE {
        STREAM::disable 
        STREAM::expression "@Hello@45678@ @Goodbye@12345@"
        if { !($uri contains "somefile.xml") || !($uri contains "/some/folder/") } {
           STREAM::enable
        }
    }
    

     

     

  • Thank you both for your responses. It appears the text wasn't being replaced due to compression. I changed the irule to include:

    
    when HTTP_REQUEST {
    
        Disable the stream filter for all requests
       STREAM::disable
    
         remove the compression offerings from the client
       HTTP::header remove "Accept-Encoding"
    }
    when HTTP_RESPONSE {
    
        Check if response type is text
       if {[HTTP::header value Content-Type] contains "text"}{
    
           Replace
          STREAM::expression {@Hello@12345@}
    
           Enable the stream filter for this response only
          STREAM::enable
       }
    } 

    I think the 'overload' function referred to by Michael will come in usefull when we go live.
  • Glad to hear that you got it worked out.

     

     

    The multiple stream replacements is something that we use in Development and Model so that the Development Staff can code everything for Production but when testing all of Hyperlinks and such are changed for the environment they are testing in.

     

     

    They seem to like it since it makes their life easier.