FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #117 from Bludwarf/master · ws-java/unirest-java@46f50eb · GitHub

Commit 46f50eb

Browse files
Merge pull request Kong#117 from Bludwarf/master
Issue Kong#73 fix alternative
2 parents fe80740 + b83c1c3 commit 46f50eb

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

‎src/main/java/com/mashape/unirest/http/Headers.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ public class Headers extends HashMap<String, List<String>> {
88
private static final long serialVersionUID = 71310341388734766L;
99

1010
public String getFirst(Object key) {
11-
Object lowerCasedKey = key instanceof String ? ((String) key).toLowerCase() : key;
12-
List<String> list = get(lowerCasedKey);
11+
List<String> list = get(key);
1312
if (list != null && list.size() > 0) {
1413
return list.get(0);
1514
}
1615
return null;
1716
}
18-
17+
1918
}

‎src/main/java/com/mashape/unirest/http/HttpResponse.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClas
5555

5656
Header[] allHeaders = response.getAllHeaders();
5757
for (Header header : allHeaders) {
58-
String headerName = header.getName().toLowerCase();
58+
String headerName = header.getName();
5959
List<String> list = headers.get(headerName);
6060
if (list == null)
6161
list = new ArrayList<String>();
@@ -122,6 +122,10 @@ public String getStatusText() {
122122
return statusText;
123123
}
124124

125+
/**
126+
* @return Response Headers (map) with <b>same case</b> as server response.
127+
* For instance use <code>getHeaders().getFirst("Location")</code> and not <code>getHeaders().getFirst("location")</code> to get first header "Location"
128+
*/
125129
public Headers getHeaders() {
126130
return headers;
127131
}

‎src/test/java/com/mashape/unirest/test/http/HeadersTest.java‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/test/java/com/mashape/unirest/test/http/UnirestTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,4 +796,15 @@ public void testPostProvidesSortedParams() throws IOException {
796796
String body = IOUtils.toString(content, "UTF-8");
797797
assertEquals("x=X&y=Y&z=Z", body);
798798
}
799+
800+
@Test
801+
public void testHeaderNamesCaseSensitive() {
802+
// Verify that header names are the same as server (case sensitive)
803+
final Headers headers = new Headers();
804+
headers.put("Content-Type", Arrays.asList("application/json"));
805+
806+
assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("cOnTeNt-TyPe"));
807+
assertEquals("Only header \"Content-Type\" should exist", null, headers.getFirst("content-type"));
808+
assertEquals("Only header \"Content-Type\" should exist", "application/json", headers.getFirst("Content-Type"));
809+
}
799810
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL