From d41d67fa942818cadac5fe5c984eeb70d1f0b574 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 8 Mar 2021 22:39:07 +0100 Subject: [PATCH] Request factory classes to re-use `Method#normalizedValueOf` --- .../http/async/methods/BasicHttpRequests.java | 16 ++-------------- .../http/async/methods/SimpleHttpRequests.java | 16 ++-------------- .../classic/methods/ClassicHttpRequests.java | 12 ++---------- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java index 02e236626..340e9cffe 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/BasicHttpRequests.java @@ -28,12 +28,10 @@ package org.apache.hc.client5.http.async.methods; import java.net.URI; -import java.util.Locale; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.Method; import org.apache.hc.core5.http.message.BasicHttpRequest; -import org.apache.hc.core5.util.Args; /** * Common HTTP methods using {@link BasicHttpRequest} as a HTTP request message representation. @@ -42,12 +40,6 @@ import org.apache.hc.core5.util.Args; */ public final class BasicHttpRequests { - // TODO Next version of HttpCore: - // Method.normalizedValueOf(method) - private static Method normalizedValueOf(final String method) { - return Method.valueOf(Args.notNull(method, "method").toUpperCase(Locale.ROOT)); - } - /** * Creates a new BasicHttpRequest for the given {@code method} and {@code String} URI. * @@ -56,9 +48,7 @@ public final class BasicHttpRequests { * @return A new BasicHttpRequest. */ public static BasicHttpRequest create(final String method, final String uri) { - // TODO Next version of HttpCore: - // return create(Method.normalizedValueOf(method), uri); - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } /** @@ -69,9 +59,7 @@ public final class BasicHttpRequests { * @return A new BasicHttpRequest. */ public static BasicHttpRequest create(final String method, final URI uri) { - // TODO Next version of HttpCore: - // return create(Method.normalizedValueOf(method), uri); - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } public static BasicHttpRequest delete(final String uri) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java index eb448158c..d89b45fa7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/SimpleHttpRequests.java @@ -28,11 +28,9 @@ package org.apache.hc.client5.http.async.methods; import java.net.URI; -import java.util.Locale; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.Method; -import org.apache.hc.core5.util.Args; /** * Common HTTP methods using {@link SimpleHttpRequest} as a HTTP request message representation. @@ -41,12 +39,6 @@ import org.apache.hc.core5.util.Args; */ public final class SimpleHttpRequests { - // TODO Next version of HttpCore: - // Method.normalizedValueOf(method) - private static Method normalizedValueOf(final String method) { - return Method.valueOf(Args.notNull(method, "method").toUpperCase(Locale.ROOT)); - } - /** * Creates a new BasicHttpRequest for the given {@code method} and {@code String} URI. * @@ -55,9 +47,7 @@ public final class SimpleHttpRequests { * @return A new BasicHttpRequest. */ public static SimpleHttpRequest create(final String method, final String uri) { - // TODO Next version of HttpCore: - // return create(Method.normalizedValueOf(method), uri); - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } /** @@ -68,9 +58,7 @@ public final class SimpleHttpRequests { * @return A new BasicHttpRequest. */ public static SimpleHttpRequest create(final String method, final URI uri) { - // TODO Next version of HttpCore: - // return create(Method.normalizedValueOf(method), uri); - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } public static SimpleHttpRequest delete(final String uri) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java index 02287c2bc..d7efc284f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/methods/ClassicHttpRequests.java @@ -28,12 +28,10 @@ package org.apache.hc.client5.http.classic.methods; import java.net.URI; -import java.util.Locale; import org.apache.hc.core5.http.Method; import org.apache.hc.core5.util.Args; - /** * Common HTTP methods using {@link HttpUriRequest} as a HTTP request message representation. *

@@ -44,12 +42,6 @@ import org.apache.hc.core5.util.Args; */ public final class ClassicHttpRequests { - private static Method normalizedValueOf(final String method) { - // TODO Next version of HttpCore: - // Method.normalizedValueOf(method) - return Method.valueOf(Args.notNull(method, "method").toUpperCase(Locale.ROOT)); - } - /** * Creates a new HttpUriRequest for the given {@code Method} and {@code String} URI. * @@ -101,7 +93,7 @@ public final class ClassicHttpRequests { * @return A new HttpUriRequest. */ public static HttpUriRequest create(final String method, final String uri) { - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } /** @@ -114,7 +106,7 @@ public final class ClassicHttpRequests { * @return A new HttpUriRequest. */ public static HttpUriRequest create(final String method, final URI uri) { - return create(normalizedValueOf(method), uri); + return create(Method.normalizedValueOf(method), uri); } public static HttpUriRequest delete(final String uri) {