HTTP retry on 404 pre-9.2.0

Problem this snippet solves:

This rule replaces the functionality of LB::reselect and HTTP::retry for pre-9.2.0 boxes. The rule looks to see if the server responds with a 404. If the server's response is a 404 it attaches a cookie and sends to the other server in the pool based upon data in the cookie.

How to use this snippet:

Note: replaced spaces in the cookie value with underscores as cookie values cannot contain spaces.

Code :

when HTTP_REQUEST { 
     set redirectURL [HTTP::host][HTTP::uri] 
     if { not [HTTP::cookie exists retryCookie]  } { 
          set priorServer                "" 
          set priorServerPort      "" 
          set priorTimes                0 
          log local0. "First request" 
     } else { 
        set priorServer           [getfield [HTTP::cookie retryCookie] "_" 1 ] 
        set priorServerPort [getfield [HTTP::cookie retryCookie] "_" 2 ] 
          set priorTimes           [getfield [HTTP::cookie retryCookie] "_" 3 ] 
          if { $priorTimes > 1 } { 
               HTTP::respond 200 content "

file not found

" } elseif { $priorServer equals "10.0.2.10"} { pool test_pool member 10.0.2.10 80 } else { pool test_pool member 10.0.2.11 80 } } } when LB_SELECTED { set poolName [getfield [LB::server] " " 1] set priorServer [getfield [LB::server] " " 2] set priorServerPort [getfield [LB::server] " " 3] } when HTTP_RESPONSE { if { [HTTP::status] starts_with "4" } { if { $priorTimes < 2 } { log local0.info "Status: [HTTP::status] " incr priorTimes log local0.info "Server1 priorTimes after incr: $priorTimes" set tmpCookie "$priorServer_$priorServerPort_$priorTimes" HTTP::cookie insert name retryCookie value $tmpCookie domain [HTTP::host] HTTP::respond 302 Location "http://$redirectURL" set-cookie "retryCookie=$tmpCookie" #HTTP::respond 302 Location "http://$redirectURL" #HTTP::redirect http://$redirectURL } else { HTTP::respond 200 content "

file not found

" } } }
Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment