HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too
This commit is contained in:
parent
9552d5dd1d
commit
742bc47a80
|
@ -37,7 +37,7 @@ import org.apache.hc.core5.http.HttpStatus;
|
|||
/**
|
||||
* 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 class DefaultBackoffStrategy implements ConnectionBackoffStrategy {
|
|||
|
||||
@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 class TestDefaultBackoffStrategy {
|
|||
}
|
||||
|
||||
@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…
Reference in New Issue