Skip to content

Commit 2175dbe

Browse files
committed
fixing http client
1 parent 4d54312 commit 2175dbe

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 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,21 @@ 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+
String body = "";
92+
if (code < HttpStatus.SC_OK || code >= HttpStatus.SC_MULTIPLE_CHOICES) {
9393
statusMessage = response.getReasonPhrase();
94+
_log.warn(String.format("Response status was: %s. Reason: %s", code, statusMessage));
95+
} else {
96+
body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
9497
}
9598

96-
return new SplitHttpResponse(response.getCode(),
99+
return new SplitHttpResponse(code,
97100
statusMessage,
98-
EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8),
101+
body,
99102
Arrays.stream(response.getHeaders()).map(
100-
h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
103+
h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
101104
.collect(Collectors.toList()));
102-
// response.getHeaders());
103105
} catch (Exception e) {
104106
throw new IllegalStateException(String.format("Problem in http get operation: %s", e), e);
105107
} finally {

0 commit comments

Comments
 (0)