You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by mi...@apache.org on 2019/11/27 11:55:25 UTC

[httpcomponents-client] branch HTTPCLIENT-2020 created (now c6b8f46)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch HTTPCLIENT-2020
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.


      at c6b8f46  HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too

This branch includes the following new commits:

     new c6b8f46  HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[httpcomponents-client] 01/01: HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch HTTPCLIENT-2020
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit c6b8f46bbe8cc82fb390e99640a586d7ff6b805b
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Nov 27 12:54:27 2019 +0100

    HTTPCLIENT-2020: DefaultBackoffStrategy should include TOO_MANY_REQUESTS (429) too
---
 .../hc/client5/http/impl/classic/DefaultBackoffStrategy.java   |  5 +++--
 .../client5/http/impl/classic/TestDefaultBackoffStrategy.java  | 10 ++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/DefaultBackoffStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/DefaultBackoffStrategy.java
index b77ea20..86c7af3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/DefaultBackoffStrategy.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/DefaultBackoffStrategy.java
@@ -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;
     }
 
 }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestDefaultBackoffStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestDefaultBackoffStrategy.java
index f8614de..f46f67c 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestDefaultBackoffStrategy.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestDefaultBackoffStrategy.java
@@ -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");