Forum Discussion
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="http://site.com/images/a.jpg">.
2. Modify all src tags that are not relative to use HTTPS rather than HTTP (example: img src="http://site.com/images/a.jpg" would become img src="https://site.com/images.a.jpg")
3. Modify all Flash AC_FL_RunContent "src", "http://site.com" references to https://
I have a single expression that handles 1:
HTTP_RESPONSE:
STREAM::expression {@href\s*=\s*\"/.*?\"@@}
STREAM_MATCHED:
STREAM::replace "[string map {href=\" href=\"http://site.com} [STREAM::match]]"
I have a single expression that handles 2 and 3:
HTTP_RESPONSE:
STREAM::expression {@src=\"http://.*?\"@@\"src\", \"http://.*?\"@@}
STREAM_MATCHED:
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,
- hooleylistCirrostratusNice work in figuring out a solution. I was a bit confused by your scenario but see what you were trying to do now.
- B_Bob_10918NimbostratusI found this in documentation:
- hooleylistCirrostratusYour 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.
- B_Bob_10918NimbostratusThat 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.
- hooleylistCirrostratusThat'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:
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com