Forum Discussion

Scott_Larson's avatar
Scott_Larson
Icon for Nimbostratus rankNimbostratus
Aug 17, 2007

Regexp to scrub http response data payload

I'm trying to write an iRule with a regexp that will scour outgoing HTTP payloads and replace http with https and remove any port (and the colon preceeding the port number) - that is, scrub all outgoing urls (like http://www.example.com:8080/) and replace them with https://www.example.com/.

 

 

I've got this so far:

 

set find "http(s)*(://www.example.com)(:[0-9]+)*"

 

 

but when I try to save my iRule, I get:

 

[undefined procedure: 0-9] [0-9]

 

 

Can anyone help me please?

 

 

2 Replies

  • ha, I just found my own answer, thanks to the SSN scrubbing example. I'll use \d to denote a number rather than [0-9]. My new regexp is:

    
    set find "http(s)*(://www.example.com)(\d)+)*"

    (the frowny face above should be replaced with a colon ":" followed by a open paren "(" ... silly auto-substituting emoticons...)

  • If you know what ports are referenced in the HTTP content you might be able to use a stream profile to perform the replacement using fewer resources than buffering the response data and doing a regsub.

    Here is an example:

    
    when HTTP_RESPONSE {
       STREAM::enable
       STREAM::expression @http://www.example.com:80@http://www.example.com@@https://www.example.com:443@https://www.example.com@
    }

    The format for the stream expression is @search1@replace1@@search2@replace2@@

    See the wiki page for stream (Click here) and this post for more info (Click here).

    Aaron