|
25 | 25 | import java.io.IOException;
|
26 | 26 | import java.net.URI;
|
27 | 27 | import java.net.URISyntaxException;
|
28 |
| -import java.util.Arrays; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.HashMap; |
29 | 30 | import java.util.List;
|
30 | 31 | import java.util.Map;
|
31 | 32 | import java.util.stream.Collectors;
|
@@ -56,9 +57,24 @@ private Map<String, String[]> asQueries(final List<NameValuePair> queries) {
|
56 | 57 | .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().toArray(new String[0])));
|
57 | 58 | }
|
58 | 59 |
|
59 |
| - private Map<String, String> asHeaders(final Header[] allHeaders) { |
60 |
| - return Arrays.stream(allHeaders) |
61 |
| - .collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue)); |
| 60 | + private static Map<String, Iterable<String>> asHeaders(final Header[] httpHeaders) { |
| 61 | + Map<String, Iterable<String>> headers = new HashMap<>(); |
| 62 | + for (Header header : httpHeaders) { |
| 63 | + String key = header.getName(); |
| 64 | + List<String> values = getValues(headers, key); |
| 65 | + values.add(header.getValue()); |
| 66 | + headers.put(key, values); |
| 67 | + } |
| 68 | + |
| 69 | + return headers; |
| 70 | + } |
| 71 | + |
| 72 | + private static List<String> getValues(final Map<String, Iterable<String>> headers, final String key) { |
| 73 | + if (headers.containsKey(key)) { |
| 74 | + return (List<String>) headers.get(key); |
| 75 | + } |
| 76 | + |
| 77 | + return new ArrayList<>(); |
62 | 78 | }
|
63 | 79 |
|
64 | 80 | public final void postAction(final CloseableHttpResponse response) throws IOException {
|
|
0 commit comments