@@ -56,18 +56,18 @@ boolean retryRequest(Response response, int executionCount, Request request, Ret
5656 if (retryOptions != null ) {
5757 shouldRetryCallback = retryOptions .shouldRetry ();
5858 }
59- // Call should retry callback
60- if (shouldRetryCallback != null && !shouldRetryCallback .shouldRetry (response , executionCount , request , retryOptions .delay ())) {
61- return false ;
62- }
6359
6460 boolean shouldRetry = false ;
6561 // Status codes 429 503 504
6662 int statusCode = response .code ();
6763 // Only requests with payloads that are buffered/rewindable are supported.
6864 // Payloads with forward only streams will be have the responses returned
6965 // without any retry attempt.
70- shouldRetry = (executionCount <= retryOptions .maxRetries ()) && checkStatus (statusCode ) && isBuffered (response , request );
66+ shouldRetry =
67+ (executionCount <= retryOptions .maxRetries ())
68+ && checkStatus (statusCode ) && isBuffered (response , request )
69+ && shouldRetryCallback != null
70+ && shouldRetryCallback .shouldRetry (retryOptions .delay (), executionCount , request , response );
7171
7272 if (shouldRetry ) {
7373 long retryInterval = getRetryAfter (response , retryOptions .delay (), executionCount );
@@ -86,8 +86,9 @@ long getRetryAfter(Response response, long delay, int executionCount) {
8686 if (retryAfterHeader != null ) {
8787 retryDelay = Long .parseLong (retryAfterHeader );
8888 } else {
89- retryDelay = (long )Math .pow (2.0 , (double )executionCount ) * DELAY_MILLISECONDS ;
89+ retryDelay = (long )(( Math .pow (2.0 , (double )executionCount )- 1 )* 0.5 ) ;
9090 retryDelay = executionCount < 2 ? retryDelay : retryDelay + delay + (long )Math .random ();
91+ retryDelay *= DELAY_MILLISECONDS ;
9192 }
9293 return Math .min (retryDelay , RetryOptions .MAX_DELAY );
9394 }
@@ -99,7 +100,7 @@ boolean checkStatus(int statusCode) {
99100
100101 boolean isBuffered (Response response , Request request ) {
101102 String methodName = request .method ();
102- if (methodName .equalsIgnoreCase ("GET" ) || methodName .equalsIgnoreCase ("DELETE" ))
103+ if (methodName .equalsIgnoreCase ("GET" ) || methodName .equalsIgnoreCase ("DELETE" ) || methodName . equalsIgnoreCase ( "HEAD" ) || methodName . equalsIgnoreCase ( "OPTIONS" ) )
103104 return true ;
104105
105106 boolean isHTTPMethodPutPatchOrPost = methodName .equalsIgnoreCase ("POST" ) ||
0 commit comments