You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/01/28 19:51:32 UTC

[httpcomponents-core] 01/01: 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.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 0867704ec4bce730442ae2c60a868c1d15ef2cde
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)
---
 RELEASE_NOTES.txt                                        |  3 +++
 .../src/main/java/org/apache/hc/core5/http/Method.java   | 16 ++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 763ed0c..dd35f3a 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -20,6 +20,9 @@ Change Log
 
 * GitHub #188: Add PathEntity, a Path based implementation of HttpEntity. (#188)
   Contributed by Gary Gregory <garydgregory at gmail.com>
+  
+* GitHub #191: Add org.apache.hc.core5.http.Method.normalizedValueOf(String).
+  Contributed by Gary Gregory <garydgregory at gmail.com>
 
 
 Release 5.0-BETA11
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;