From da02f662934a7aa6985bf7e89e362096b9252c7f Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Sat, 15 Feb 2020 08:59:25 -0600 Subject: [PATCH] make HttpMethod not care about case --- .../main/java/kong/unirest/HttpMethod.java | 2 +- .../java/kong/unirest/HttpMethodTest.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 unirest/src/test/java/kong/unirest/HttpMethodTest.java diff --git a/unirest/src/main/java/kong/unirest/HttpMethod.java b/unirest/src/main/java/kong/unirest/HttpMethod.java index a1d09cbfb..8edbe56bb 100644 --- a/unirest/src/main/java/kong/unirest/HttpMethod.java +++ b/unirest/src/main/java/kong/unirest/HttpMethod.java @@ -49,7 +49,7 @@ private HttpMethod(String name){ } public static HttpMethod valueOf(String verb){ - return REGISTRY.computeIfAbsent(verb, HttpMethod::new); + return REGISTRY.computeIfAbsent(String.valueOf(verb).toUpperCase(), HttpMethod::new); } public Set all(){ diff --git a/unirest/src/test/java/kong/unirest/HttpMethodTest.java b/unirest/src/test/java/kong/unirest/HttpMethodTest.java new file mode 100644 index 000000000..9aa320ebf --- /dev/null +++ b/unirest/src/test/java/kong/unirest/HttpMethodTest.java @@ -0,0 +1,47 @@ +/** + * The MIT License + * + * Copyright for portions of unirest-java are held by Kong Inc (c) 2013. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package kong.unirest; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class HttpMethodTest { + + @Test + public void equalsTest() { + assertEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("GET")); + assertEquals(HttpMethod.GET, HttpMethod.GET); + assertNotEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("PUT")); + assertNotEquals(HttpMethod.GET, HttpMethod.PUT); + } + + + @Test + public void notCaseSensative() { + assertEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("get")); + } +} \ No newline at end of file