Skip to content

Commit 04aa57f

Browse files
committed
Use method isIdempotent
1 parent cad9fb7 commit 04aa57f

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/impl/TooEarlyRetryStrategy.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.hc.core5.http.HttpRequest;
4444
import org.apache.hc.core5.http.HttpResponse;
4545
import org.apache.hc.core5.http.HttpStatus;
46+
import org.apache.hc.core5.http.Method;
4647
import org.apache.hc.core5.http.protocol.HttpContext;
4748
import org.apache.hc.core5.http.protocol.HttpCoreContext;
4849
import org.apache.hc.core5.util.Args;
@@ -76,11 +77,6 @@ public final class TooEarlyRetryStrategy implements HttpRequestRetryStrategy {
7677
*/
7778
public static final String DISABLE_EARLY_DATA_ATTR = "http.client.tls.early_data.disable";
7879

79-
// Java 8–friendly immutable set of idempotent methods (no Set.of).
80-
private static final Set<String> IDEMPOTENT = Collections.unmodifiableSet(
81-
new HashSet<String>(Arrays.asList("GET", "HEAD", "OPTIONS", "TRACE", "PUT", "DELETE"))
82-
);
83-
8480
private final int maxRetries;
8581
private final boolean include429and503;
8682
private final HttpRequestRetryStrategy delegateForExceptions; // optional, may be null
@@ -179,7 +175,7 @@ public boolean retryRequest(
179175
return false;
180176
}
181177

182-
if (!IDEMPOTENT.contains(original.getMethod())) {
178+
if (!Method.normalizedValueOf(original.getMethod()).isIdempotent()) {
183179
return false;
184180
}
185181

httpclient5/src/main/java/org/apache/hc/client5/http/impl/TooEarlyStatusRetryExec.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hc.core5.http.HttpEntity;
4040
import org.apache.hc.core5.http.HttpException;
4141
import org.apache.hc.core5.http.HttpStatus;
42+
import org.apache.hc.core5.http.Method;
4243
import org.apache.hc.core5.http.io.entity.EntityUtils;
4344

4445
/**
@@ -51,9 +52,6 @@
5152
public final class TooEarlyStatusRetryExec implements ExecChainHandler {
5253

5354
private static final String RETRIED_ATTR = "http.client.too_early.retried";
54-
private static final Set<String> IDEMPOTENT = Collections.unmodifiableSet(
55-
new HashSet<>(Arrays.asList("GET", "HEAD", "OPTIONS", "TRACE", "PUT", "DELETE"))
56-
);
5755

5856
private final boolean include429and503;
5957

@@ -74,7 +72,7 @@ public ClassicHttpResponse execute(
7472
|| code == HttpStatus.SC_SERVICE_UNAVAILABLE);
7573

7674
final boolean alreadyRetried = Boolean.TRUE.equals(scope.clientContext.getAttribute(RETRIED_ATTR));
77-
final boolean idempotent = IDEMPOTENT.contains(request.getMethod());
75+
final boolean idempotent = Method.normalizedValueOf(request.getMethod()).isIdempotent();
7876
final HttpEntity reqEntity = request.getEntity();
7977
final boolean repeatable = reqEntity == null || reqEntity.isRepeatable();
8078

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/TooEarlyStatusRetryAsyncExec.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.hc.core5.http.HttpRequest;
4747
import org.apache.hc.core5.http.HttpResponse;
4848
import org.apache.hc.core5.http.HttpStatus;
49+
import org.apache.hc.core5.http.Method;
4950
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
5051
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
5152
import org.apache.hc.core5.http.nio.CapacityChannel;
@@ -60,9 +61,6 @@
6061
public final class TooEarlyStatusRetryAsyncExec implements AsyncExecChainHandler {
6162

6263
private static final String RETRIED_ATTR = "http.client.too_early.retried";
63-
private static final Set<String> IDEMPOTENT = Collections.unmodifiableSet(
64-
new HashSet<>(Arrays.asList("GET", "HEAD", "OPTIONS", "TRACE", "PUT", "DELETE"))
65-
);
6664

6765
private final boolean include429and503;
6866

@@ -95,7 +93,7 @@ public AsyncDataConsumer handleResponse(
9593

9694
final boolean alreadyRetried =
9795
Boolean.TRUE.equals(scope.clientContext.getAttribute(RETRIED_ATTR));
98-
final boolean idempotent = IDEMPOTENT.contains(request.getMethod());
96+
final boolean idempotent = Method.normalizedValueOf(request.getMethod()).isIdempotent();
9997
final boolean repeatable = entityProducer == null || entityProducer.isRepeatable();
10098

10199
if (eligible && !alreadyRetried && idempotent && repeatable) {

0 commit comments

Comments
 (0)