Forum Discussion

Brandon_Mason_3's avatar
Brandon_Mason_3
Icon for Nimbostratus rankNimbostratus
Aug 24, 2006

iRule for HTTP Response

If anyone could help us with a few examples of how to write an iRule to meet this requirement it would be greatly appreciated.

 

 

Here’s a rough requirement summary:

 

 

For an incoming http request for the uri:

 

http://www.yoursite.com/sample.js

 

 

IF the response to the request, returned by a server sitting behind the load balancer is:

 

a. NOT status 200 or

 

b. IS status 200 but NOT completed within X secs

 

 

THEN return this canned http response:

 

 

-- BEGIN OUTPUT --

 

/*

 

* Load Balancer

 

*/

 

 

array_variable = [];

 

 

-- END OUTPUT --

 

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    The rule logic would be something like this:
    when RULE_INIT {
     set ::timeout 5 ;  seconds
    }
    when HTTP_REQUEST {
     set reqTime [clock seconds]
    }
    when HTTP_RESPONSE {
     if {not ([HTTP::status] == 200) or \
      [clock seconds] > [expr $reqTime + $::timeout]}{
       HTTP::respond ...
      }
     }
    }
    where the response is imbedded in the code with the HTTP::respond command as discussed here: http://devcentral.f5.com/Default.aspx?tabid=28&view=topic&forumid=5&postid=9523

     

    Click hereHTH

     

    /deb
  • Using this rule, if one of my servers takes 10 seconds to process a request, do I get the fixed response after 10 seconds (time it takes the server to respond) or 5 seconds (the defined timeout)? The comments from http://devcentral.f5.com/Default.aspx?tabid=28&view=topic&forumid=5&postid=9663 seem ominous.
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account

     

    Hopefully soon we'll have the long-awaited timeout mentioned in the post you reference...

     

     

    For this request, to catch the explicit condition "IS status 200 but NOT completed within X secs", we'd have to see the server response. With the above iRule, you would get the fixed response when HTTP_RESPONSE event is triggered (when the server responds - or never if it doesn't.)

     

     

    HTH

     

    /deb