Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions client/src/main/java/io/split/service/SplitHttpClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.HttpEntities;
Expand All @@ -19,7 +20,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hc.core5.http.HttpRequest;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -87,19 +87,25 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map<String, List<Str
}

String statusMessage = "";
if (response.getCode() < HttpStatus.SC_OK || response.getCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
_log.warn(String.format("Response status was: %s. Reason: %s", response.getCode(),
response.getReasonPhrase()));
int code = response.getCode();
if (code < HttpStatus.SC_OK || code >= HttpStatus.SC_MULTIPLE_CHOICES) {
statusMessage = response.getReasonPhrase();
_log.warn(String.format("Response status was: %s. Reason: %s", code, statusMessage));
}

String body = "";
try {
body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
} catch (Exception e) {
_log.warn("Error parsing Response.body", e);
}

return new SplitHttpResponse(response.getCode(),
return new SplitHttpResponse(code,
statusMessage,
EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8),
body,
Arrays.stream(response.getHeaders()).map(
h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
.collect(Collectors.toList()));
// response.getHeaders());
} catch (Exception e) {
throw new IllegalStateException(String.format("Problem in http get operation: %s", e), e);
} finally {
Expand Down
Loading