Skip to content

Commit

Permalink
make HttpMethod not care about case
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Feb 15, 2020
1 parent 8872acb commit da02f66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion unirest/src/main/java/kong/unirest/HttpMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpMethod> all(){
Expand Down
47 changes: 47 additions & 0 deletions unirest/src/test/java/kong/unirest/HttpMethodTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit da02f66

Please sign in to comment.