Skip to content

Commit ae9c911

Browse files
authored
Merge pull request #553 from splitio/fix/http-client-bad-request
Fixing http client
2 parents 4d54312 + 2dc5150 commit ae9c911

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

client/src/main/java/io/split/service/SplitHttpClientImpl.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
1212
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
1313
import org.apache.hc.core5.http.ContentType;
14+
import org.apache.hc.core5.http.HttpRequest;
1415
import org.apache.hc.core5.http.HttpStatus;
1516
import org.apache.hc.core5.http.io.entity.EntityUtils;
1617
import org.apache.hc.core5.http.io.entity.HttpEntities;
@@ -19,7 +20,6 @@
1920
import java.io.IOException;
2021
import java.net.URI;
2122
import java.net.URISyntaxException;
22-
import org.apache.hc.core5.http.HttpRequest;
2323
import java.nio.charset.StandardCharsets;
2424
import java.util.Arrays;
2525
import java.util.Collections;
@@ -87,19 +87,25 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map<String, List<Str
8787
}
8888

8989
String statusMessage = "";
90-
if (response.getCode() < HttpStatus.SC_OK || response.getCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
91-
_log.warn(String.format("Response status was: %s. Reason: %s", response.getCode(),
92-
response.getReasonPhrase()));
90+
int code = response.getCode();
91+
if (code < HttpStatus.SC_OK || code >= HttpStatus.SC_MULTIPLE_CHOICES) {
9392
statusMessage = response.getReasonPhrase();
93+
_log.warn(String.format("Response status was: %s. Reason: %s", code, statusMessage));
94+
}
95+
96+
String body = "";
97+
try {
98+
body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
99+
} catch (Exception e) {
100+
_log.warn("Error parsing Response.body", e);
94101
}
95102

96-
return new SplitHttpResponse(response.getCode(),
103+
return new SplitHttpResponse(code,
97104
statusMessage,
98-
EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8),
105+
body,
99106
Arrays.stream(response.getHeaders()).map(
100107
h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
101108
.collect(Collectors.toList()));
102-
// response.getHeaders());
103109
} catch (Exception e) {
104110
throw new IllegalStateException(String.format("Problem in http get operation: %s", e), e);
105111
} finally {

0 commit comments

Comments
 (0)