mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-16 23:16:33 +00:00
HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too
This commit is contained in:
parent
9552d5dd1d
commit
742bc47a80
@ -37,7 +37,7 @@
|
||||
/**
|
||||
* This {@link ConnectionBackoffStrategy} backs off either for a raw
|
||||
* network socket or connection timeout or if the server explicitly
|
||||
* sends a 503 (Service Unavailable) response.
|
||||
* sends a 429 (Too Many Requests) or a 503 (Service Unavailable) response.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@ -51,7 +51,8 @@ public boolean shouldBackoff(final Throwable t) {
|
||||
|
||||
@Override
|
||||
public boolean shouldBackoff(final HttpResponse resp) {
|
||||
return resp.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
|
||||
return resp.getCode() == HttpStatus.SC_TOO_MANY_REQUESTS ||
|
||||
resp.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -71,9 +71,15 @@ public void backsOffForServiceUnavailable() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotBackOffForNon503StatusCodes() {
|
||||
public void backsOffForTooManyRequests() {
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpStatus.SC_TOO_MANY_REQUESTS, "Too Many Requests");
|
||||
assertTrue(impl.shouldBackoff(resp));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotBackOffForNon429And503StatusCodes() {
|
||||
for(int i = 100; i <= 599; i++) {
|
||||
if (i == HttpStatus.SC_SERVICE_UNAVAILABLE) {
|
||||
if (i== HttpStatus.SC_TOO_MANY_REQUESTS || i == HttpStatus.SC_SERVICE_UNAVAILABLE) {
|
||||
continue;
|
||||
}
|
||||
final HttpResponse resp = new BasicHttpResponse(i, "Foo");
|
||||
|
Loading…
x
Reference in New Issue
Block a user