cancel
Showing results for 
Search instead for 
Did you mean: 

iRule to send http status 400 code when pool is offline for a web service call

Kiran_Kumar
Nimbostratus
Nimbostratus

Hi Friends,

 

Could anyone help me with an iRule to send a http 400 status when all the pool members in a pool are offline. Typically I would use a go-away iRule with a redirect url. but my case is dealing with web service calls not using the browser component, redirect url doesnt serve my purpose. I would want something like http 400 status code to be issued by F5 when all pool members are offline. Thanks for your help.

 

-KK

 

8 REPLIES 8

JG
Cumulonimbus
Cumulonimbus

The fallback server (in http profile) should be able to handle this.

 

JG
Cumulonimbus
Cumulonimbus

However, the redirect solution leaves much to be improved. You can implement an irule to read from an ifile to avoid any redirect, so the end-user can simply do a page reload to check if the site back up again.

 

This has been such an FAQ and use case that it warrants a feature request to F5.

 

marco_octavian_
Nimbostratus
Nimbostratus

Try this untested iRule.

 

when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 400 content "Bad Request page\ 400 - The request could not be understood by the server due to malformed syntax. \ " "Content-Type" "text/html" return } }

JG
Cumulonimbus
Cumulonimbus

You probably want to add some cache control directives to prevent the 400 page from being cached by any means.

 

marco_octavian_
Nimbostratus
Nimbostratus

Scratch that first irule. It was untested and has flaws. I agree with Jie about the no-cache. Give this one a try.

 

when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 400 content " Bad Request page 400 - The request could not be understood by the server due to malformed syntax. " Cache-Control No-Cache Pragma No-Cache" } }

Nice solution Marco. You could replace the ""s with {} around the content to avoid having to escape any meta-characters in the fuller HTML that an admin might use: HTTP::respond 400 content {...} header1 value1 headerN valueN

Marco, Thanks very much for your solution. Could you please advise how to make sure that the client doesnt know that its my F5 that sends this message. In other words, I dont want the client to be aware of my F5, can we put some dummy server name. If so how do we get it accomplished as part of the above solution. I am new to F5 iRule coding, so need your help if you have any suggestions. Thanks again for you and all the friends who responded to my question.

Colin_Walker_12
Historic F5 Account

HTTP Status 400 pages shouldn't be cached, if clients are acting appropriately. You know, since all web clients always response exactly according to RFCs right? Right??

 

Still...not a terrible idea to force said behavior. Good call, Jie. 😉

 

Colin