Forum Discussion

B_Bob_10918's avatar
Icon for Nimbostratus rankNimbostratus
Jun 02, 2011

multiple match-based stream replacements?

EDIT: I posted this to the wrong category. I figured out the solution: Use more than one expression and use conditionals in your STREAM_MATCHED.








I need to do the following three operations to certain HTTP responses:




1. Modify all relative hrefs to full URL (example: a href="/images/a.jpg" would become a href="">.




2. Modify all src tags that are not relative to use HTTPS rather than HTTP (example: img src="" would become img src="")




3. Modify all Flash AC_FL_RunContent "src", "" references to https://






I have a single expression that handles 1:




STREAM::expression {@href\s*=\s*\"/.*?\"@@}




STREAM::replace "[string map {href=\" href=\"} [STREAM::match]]"






I have a single expression that handles 2 and 3:




STREAM::expression {@src=\"http://.*?\"@@\"src\", \"http://.*?\"@@}




STREAM::replace "[string map {http:// https://} [STREAM::match]]"








Can these be combined somehow and/or is it possible to use more than one iRule? Apologies for my ignorance, I'm new to iRules and TCL.




Thank you,






5 Replies

  • Nice work in figuring out a solution. I was a bit confused by your scenario but see what you were trying to do now.



  • I found this in documentation:


    "The stream profile performs all replacements in single pass, so data changed once will not be changed again in the same operation even if it matches another replacement pattern after the initial replacement."



    Does this mean that it's not possible to have more than one iRule containing a STREAM::expression modify a HTTP_RESPONSE?
  • Your rule should work. The single pass restriction would prevent you from using the second match expression to match on an updated version of the source string that the first match/replace updated. In other words, you can't do rewrites with a stream profile which overlap. Hope that makes sense.



  • That makes sense and my rule does work. But what I want to understand is if I can have two separate iRules both of which use different stream expressions, assign them priorities, and have them modify a single HTTP response. So far in my tests the answer is no but it should be clear to anyone reading my posts that I don't know what I'm talking about. Thanks for your help mate.
  • That's a good question. I don't think you can do this. I think if you call STREAM::expression multiple times, you'd just overwrite the past config with the current one. Worst case if you really need this type of functionality, you could potentially use a virtual targeting a virtual. That might work to allow you to apply two stream expressions to the same response. You can use the virtual command to target a virtual server from another one: