Request factory classes to re-use `Method#normalizedValueOf`

This commit is contained in:
Oleg Kalnichevski 2021-03-08 22:39:07 +01:00
parent b6b89a7296
commit d41d67fa94
3 changed files with 6 additions and 38 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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.
* <p>
@ -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) {