Forum Discussion

Tony_Bourke_935's avatar
Tony_Bourke_935
Icon for Nimbostratus rankNimbostratus
Sep 10, 2010

iRules HTTP_RESPONSE based on Pool?

Is there a way to do switch or if statements based on the pool the response came from? For example: I'm dividing up traffic into two pools based on the URI. Pool "http" and pool "gopher". I need to rewrite http:// to https:// if the response was sent to pool "http", and rewrite http:// to gopher:// if it came from pool "gopher".

5 Replies

  • Here's the HTTP_RESPONSE wiki which also contains available commands:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP_RESPONSE.html

     

     

    Do the servers in your HTTP and Gopher pools share the same IPs? If they don't, you could look at IP::server_addr and rewrite based on that.
  • Hi Chris,

     

     

    Yeah, I was hoping to avoid having to define the pool members in the iRule itself, then having two separate places to worry about in terms of keeping pool members updated. If I add a server into a pool, I'd have to remember to add the server into the pool list variable in the iRule.

     

     

    The HTTP_REPONSE wiki page doesn't seem to have any way to define an action to be taken depending on the pool that the HTTP_REQUEST was sent to.
  • I suppose you could set a variable in the LB_SELECTED event that you check for in your response event...
  • Hi Tony: would it be possible to simply set a variable in your HTTP_REQUEST event that you reference on HTTP_RESPONSE? For example, you've already made a decision to send some traffic to one pool or the other based on uri, so you should be able to do this.

     

     

    Here's some non-tested, free form code as an example.

     

    
    when HTTP_REQUEST {
      if {HTTP::uri equals '/foo'} {
        set selected 'gopher'
        pool gopher
        }  else { 
        set selected 'http'
        pool http
        }
    }
    when HTTP_RESPONSE {
      log local0. "This response is coming from pool $selected..."
    }
    

     

    I'm sure I've got a fat-finger or two in here but hopefully it'll give you an idea of what I am thinking here.

     

     

    -Matt
  • By the way you could also use LB::server in the request event to set the pool name of the node, if I recall...so it would look something like:

    
    set selected [LB::server pool]
    

    ...but the first option may make more sense.

    -Matt