You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2020/01/28 19:40:36 UTC
[httpcomponents-core] branch master updated: Add
org.apache.hc.core5.http.Method.normalizedValueOf(String) for use by (#191)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/master by this push:
new e7f5f33 Add org.apache.hc.core5.http.Method.normalizedValueOf(String) for use by (#191)
e7f5f33 is described below
commit e7f5f33db15941f771a5c8b898d0214bdc86fe34
Author: Gary Gregory <ga...@users.noreply.github.com>
AuthorDate: Tue Jan 28 14:40:28 2020 -0500
Add org.apache.hc.core5.http.Method.normalizedValueOf(String) for use by (#191)
* Add org.apache.hc.core5.http.Method.normalizedValueOf(String) for use by
httpclient5.
* Changer per Oleg's request.
---
.../src/main/java/org/apache/hc/core5/http/Method.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/Method.java b/httpcore5/src/main/java/org/apache/hc/core5/http/Method.java
index 81bd758..0b3b627 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/Method.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/Method.java
@@ -29,6 +29,8 @@ package org.apache.hc.core5.http;
import java.util.Locale;
+import org.apache.hc.core5.util.Args;
+
/**
* Common HTTP methods defined by the HTTP spec.
*
@@ -67,7 +69,7 @@ public enum Method {
return false;
}
try {
- return valueOf(value.toUpperCase(Locale.ROOT)).safe;
+ return normalizedValueOf(value).safe;
} catch (final IllegalArgumentException ex) {
return false;
}
@@ -78,12 +80,22 @@ public enum Method {
return false;
}
try {
- return valueOf(value.toUpperCase(Locale.ROOT)).idempotent;
+ return normalizedValueOf(value).idempotent;
} catch (final IllegalArgumentException ex) {
return false;
}
}
+ /**
+ * Returns the Method for a normalized {@code value} of a method name.
+ *
+ * @param method A method name like {@code "delete"}, {@code "DELETE"}, or any mixed-case variant.
+ * @return the Method for the given method name.
+ */
+ public static Method normalizedValueOf(final String method) {
+ return valueOf(Args.notNull(method, "method").toUpperCase(Locale.ROOT));
+ }
+
public boolean isSame(final String value) {
if (value == null) {
return false;