Forum Discussion

Sebastian_Maniak's avatar
Dec 07, 2009

Stream iRule Help

I want this iRULE to modify the returned URL based on HTTP request.

 

 

Problem: A8001 is the local server name. It changes from server to server. We don’t want to expose local server name to external world. We don’t have the flexibility to change the code to do ‘relative’ URL redirect.

 

 

 

 

when HTTP_REQUEST {

 

set host [HTTP::header host]

 

if { [matchclass [HTTP::uri] contains $::A_URIs_no_persist] } {

 

persist none

 

pool Pool_A

 

event disable

 

}

 

}

 

when HTTP_RESPONSE {

 

STREAM::disable

 

if {[HTTP::status] ==200 and [HTTP::header value Content-Type] contains $::A_URIs_no_persist }{

 

STREAM::expression @http://A8001:8001/@http://$host/@

 

STREAM::enable

 

}

 

}

 

 

 

I have setup this iRule but it still replies with A8001:8001

 

 

Any suggestions?

 

6 Replies

  • That looks like a good start. Can you replace this portion with matchclass to check the Content-Type header against the datagroup?

    Also, can you clarify what Content-Types you want to check in the response? The Content-Type header will contain MIME types--not URIs. So you should probably change this iRule to reference a new class which contains the Content-Types you want to check.

    [HTTP::header value Content-Type] contains $::A_URIs_no_persist

    [matchclass [HTTP::header value Content-Type] contains $::mime_types_to_check]

     
     when HTTP_REQUEST { 
        set host [HTTP::host] 
        if { [matchclass [HTTP::uri] contains $::A_URIs_no_persist] } { 
           persist none 
           pool Pool_A 
        } 
     } 
     when HTTP_RESPONSE { 
        STREAM::disable 
        if {[HTTP::status] == 200 and [matchclass [HTTP::header value Content-Type] contains $::mime_types_to_check]}{ 
           STREAM::expression @http://A8001:8001/@http://$host/@ 
           STREAM::enable 
        } 
     } 
     

    Aaron
  • when HTTP_REQUEST {

     

    set orig_host [HTTP::host]

     

    set orig_uri [HTTP::uri]

     

    set orig_port [TCP::local_port]

     

    }

     

    when HTTP_RESPONSE {

     

    if { $orig_uri contains "wdsl" } {

     

    HTTP::header replace Host $orig_host

     

    TCP::local_port $orig_port

     

    }

     

     

    }
  • Hi Marc,

     

     

    Did you have a question?

     

     

    I'm guessing you want to replace references in response content to an internal hostname and port with an external hostname and port. But can you clarify this? Can you provide a sample response that you want to rewrite?

     

     

    Note that there isn't a host header in response content. The response content may contain references to a hostname though.

     

     

    Aaron
  • thanks guys i got it working.

     

     

    this is the rule i used.

     

     

    when HTTP_REQUEST {

     

    set host [HTTP::header host]

     

    if { [matchclass [HTTP::uri] contains $::A_URIs_no_persist] } {

     

    persist none

     

    pool Pool_A

     

    event disable

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

    STREAM::disable

     

    if {[HTTP::status] ==200 and [HTTP::header value Content-Type] contains "text" }{

     

    STREAM::expression "@http://A8101:8001@http://$host/@ @http://A8102:8001@http://$host/@ @http://A8103:8001@http://$host/@ @http://A8104:8001@http://$host/@ @http://A8105:8001@http://$host/@ @http://A8106:8001@http://$host/@"

     

    STREAM::enable

     

    }

     

    }

     

     

    going to add a regex to it to make it more efficient.
  • The regex could be fairly simple:

     

     

    STREAM::expression [subst -nocommands {@http://A810[0-9]:8001/@http://$host/@}]

     

     

    Make sure to test that with a 'b load' to see if the rule syntax works for your version. If you get an iRule parser error, you can try this instead:

     

     

    STREAM::expression "@http://A810\[0-9\]:8001/@http://$host/@"

     

     

    And can you clarify why you're calling 'event disable' in HTTP_REQUEST? That would prevent the HTTP_REQUEST event from triggering if a client establishes a TCP connection, makes one request for a host in your datagroup and then makes a second HTTP request on the same TCP connection.

     

     

    Aaron