forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponseHeadersHelper.java
More file actions
49 lines (45 loc) · 1.46 KB
/
Copy pathHttpResponseHeadersHelper.java
File metadata and controls
49 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.microsoft.graph.http;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import okhttp3.Headers;
import okhttp3.Response;
public class HttpResponseHeadersHelper {
/**
* Gets the response headers from OkHttp Response
*
* @param response the OkHttp response
* @return the set of headers names and value
*/
public Map<String, String> getResponseHeadersAsMapStringString(final Response response) {
final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
int index = 0;
Headers responseHeaders = response.headers();
while (index < responseHeaders.size()) {
final String headerName = responseHeaders.name(index);
final String headerValue = responseHeaders.value(index);
if (headerName == null || headerValue == null) {
break;
}
headers.put(headerName, headerValue);
index++;
}
return headers;
}
/**
* Gets the response headers from OkHttp Response
*
* @param response the OkHttp response
* @return the set of headers names and value
*/
public Map<String, List<String>> getResponseHeadersAsMapOfStringList(Response response) {
Map<String, List<String>> headerFields = response.headers().toMultimap();
// Add the response code
List<String> list = new ArrayList<>();
list.add(String.format("%d", response.code()));
headerFields.put("responseCode", list);
return headerFields;
}
}