diff --git a/client/src/main/java/io/split/client/HttpSplitChangeFetcher.java b/client/src/main/java/io/split/client/HttpSplitChangeFetcher.java index ea18a6d65..bf91d23d2 100644 --- a/client/src/main/java/io/split/client/HttpSplitChangeFetcher.java +++ b/client/src/main/java/io/split/client/HttpSplitChangeFetcher.java @@ -14,9 +14,11 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.message.BasicHeader; import org.apache.hc.core5.net.URIBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +27,8 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -93,8 +97,7 @@ public SplitChange fetch(long since, FetchOptions options) { } response = _client.execute(request); - options.handleResponseHeaders(Arrays.stream(response.getHeaders()) - .collect(Collectors.toMap(Header::getName, Header::getValue))); + options.handleResponseHeaders(readResponseHeaders(response.getHeaders())); int statusCode = response.getCode(); @@ -127,4 +130,18 @@ public SplitChange fetch(long since, FetchOptions options) { URI getTarget() { return _target; } + + private Map readResponseHeaders(Header[] headers) { + Map toReturn = new HashMap<>(); + for (Header header : headers) { + if (toReturn.containsKey(header.getName())) { + toReturn.put(header.getName(), toReturn.get(header.getName()) + "," + header.getValue()); + continue; + } + + toReturn.put(header.getName(), header.getValue()); + } + + return toReturn; + } } \ No newline at end of file diff --git a/client/src/test/java/io/split/TestHelper.java b/client/src/test/java/io/split/TestHelper.java index 39b973c78..449a692f6 100644 --- a/client/src/test/java/io/split/TestHelper.java +++ b/client/src/test/java/io/split/TestHelper.java @@ -5,6 +5,8 @@ import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpHeaders; +import org.apache.hc.core5.http.message.BasicHeader; import org.mockito.Mockito; import java.io.IOException; @@ -19,7 +21,10 @@ public static CloseableHttpClient mockHttpClient(String jsonName, int httpStatus ClassicHttpResponse httpResponseMock = Mockito.mock(ClassicHttpResponse.class); Mockito.when(httpResponseMock.getEntity()).thenReturn(entityMock); Mockito.when(httpResponseMock.getCode()).thenReturn(httpStatus); - Mockito.when(httpResponseMock.getHeaders()).thenReturn(new Header[0]); + Header[] headers = new Header[2]; + headers[0] = new BasicHeader(HttpHeaders.VIA, "HTTP/1.1 m_proxy_rio1"); + headers[1] = new BasicHeader(HttpHeaders.VIA, "HTTP/1.1 s_proxy_rio1"); + Mockito.when(httpResponseMock.getHeaders()).thenReturn(headers); CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class); Mockito.when(httpClientMock.execute(Mockito.anyObject())).thenReturn(classicResponseToCloseableMock(httpResponseMock));