Forum Discussion
DarkSideOfTheQ_
Nimbostratus
Jul 14, 2010Return status code and a retry after X value
Hello All,
I was asked today to create an iRule that returned a 503 based off the user-agent string and also a return value of some sort. I have my iRule that will give the 503 but can't quite figure out the 'retry-after' portion of the request. I did some searching and hope I haven't missed a post here, but am wondering if there is a way to return a 503 to someone and tell them to try again in X amount of time???
TIA
-DarkSide
7 Replies
- hoolio
Cirrostratus
Hi DarkSide,
You can use HTTP::respond to send a specific response code and append a list of header names and values. I think something like this should work:when HTTP_REQUEST { Check if the User-Agent header if {[HTTP::header User-Agent] contains "some user-agent string"}{ Send a 503 response with a Retry-After header set to 5 minutes Don't include the Server: BigIP header (noserver) Retry-After described in: http://tools.ietf.org/html/rfc2616section-14.37 HTTP::respond 503 noserver "Retry-After" 300 } }
Aaron - DarkSideOfTheQ_
Nimbostratus
Hi Hoolio,
I appreciate the assistance. I wasn't sure about appending the "Retry-After" header after I had the 503 in there. I had to modify the Retry-After part as it wouldn't accept it (I'm running 9.2.4 if that makes a difference?)
Here is what I got working if someone comes across the need for something like this as I did.
when HTTP_REQUEST {
Check the User-Agent header
switch -glob [string tolower [HTTP::header User-Agent]] {
"*msnbot*" -
"*fast-*" -
"*yahoo-newscrawler*" -
"*baiduspider*" -
"*google*" {
Send a 503 response with a Retry-After header set to 3 hours
Don't include the Server: BigIP header (noserver)
HTTP::respond 503 noserver Retry-After:10800
}
}
} - hoolio
Cirrostratus
When you say it doesn't work, do you mean that the Retry-After header isn't set in the response? Else, can you try testing with curl from the LTM command line:
curl -v --user-agent "google" http://1.1.1.1/
Can you replace the colon with a space in Retry-After 10800:when HTTP_REQUEST { HTTP::respond 503 noserver Retry-After 3 }
> GET /test.123 HTTP/1.1
> User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: 7.7.7.18
> Accept: */*
>
< HTTP/1.0 503 Service Unavailable
< Retry-After: 3
< Connection: Keep-Alive
< Content-Length: 0
Aaron - hoolio
Cirrostratus
Sorry, I just notice you said you're running 9.2.x. The noserver flag was added in 9.4 to remove the Server: BigIP header. You can use this instead:when HTTP_REQUEST { HTTP::respond 503 Retry-After 3 }
Aaron - DarkSideOfTheQ_
Nimbostratus
When I tried to use "Retry-After" 10800 the LTM threw an error when creating the new iRule, so I changed that to "Retry-After:10800" and it accepted it.
I've changed my HTTP:RESPOND line to this, we'd like them to come back in 3 hours.
HTTP::respond 503 Retry-After 10800
Does that look OK? - hoolio
Cirrostratus
That's exactly it.
Aaron - DarkSideOfTheQ_
Nimbostratus
Excellent!!!
Once again Hoolio...many thanks to you!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
