Forum Discussion

Juan_Carlos_Rom's avatar
Juan_Carlos_Rom
Icon for Altostratus rankAltostratus
Jul 18, 2022

irule replace and modify uri and response

Hello everyone, I have a problem with the irule that I've develop to the response from the server. To put them in context the user access to the app with three different uri: 1. https://example.co...
  • candc's avatar
    Jul 18, 2022

    If I understand you correctly, you need to alter the stream expression in your HTTP_RESPONSE event, based either on the pool that was selected or the URI you received, during the HTTP_REQUEST event. 

    Note that you may need to capture that in a variable in the HTTP_REQUEST event, and check the variable in the HTTP_RESPONSE event, because you might only be able to use certain API functions inside certain events.

    Something like:

    when HTTP_REQUEST {
    set orig_uri [HTTP::uri]
    # the rest of your logic
    }
    when HTTP_RESPONSE {
    STREAM::disable
    if {([HTTP::status] == 200) && ([HTTP::header value Content-Type] contains "text") } {
    switch -glob -- [string tolower $orig_uri] {
    "/ris1*" {
    STREAM::expression {@http:@https:@ @/[Nn]ovaris@/ris1@}
    }
    "/ris2*" {
    STREAM::expression {@http:@https:@ @/[Nn]ovaris@/ris2@}
    }
    "/ris3*" {
    STREAM::expression {@http:@https:@ @/[Nn]ovaris@/ris3@}
    }
    }
     STREAM::enable
    }
    }

    (There are other optimisations that might shorten this, but you should get the gist)

    Note that I have also changed the expression for your http/https rewrite to http:/https: (note the colon), so that any https:// URI returned by the downstream server is not rewritten to httpss://.

    You may also need to handle a case-sensitive response back from the downstream server (I presume you would need to rewrite /Novaris or /novaris for instance).  To that end, you may need to make your stream search expression something like...

    @/[Nn][Oo][Vv][Aa][Rr][Ii][Ss]@/ris1@

    ...so it handles upper- and lower-case.

  • Enes_Afsin_Al's avatar
    Jul 18, 2022

    Hi,

    If the stream expression string starts or ends with space, it won't work.
    It looks neater with space, but it shouldn't. 🙂

    # This will work
    STREAM::expression {@IE@Apache@ @Windows@Linux@}
    
    # and this will work
    STREAM::expression [list "@IE@Apache" "@Windows@Linux@"]
    
    # but this will NOT work-- notice the space between the '{' and the '@'
    STREAM::expression { @IE@Apache@ @Windows@Linux@ }

    REF: https://clouddocs.f5.com/api/irules/STREAM__expression.html