Skip to content

Commit 3644184

Browse files
committed
release http entity resorces once we get back the response and handle it
1 parent 4d76cf7 commit 3644184

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/postmarkapp/postmark/client/HttpClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import org.apache.hc.client5.http.config.RequestConfig;
44
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
55
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
6-
import org.apache.hc.client5.http.impl.classic.HttpClients;
76
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
87
import org.apache.hc.core5.http.ClassicHttpRequest;
98
import org.apache.hc.core5.http.ContentType;
9+
import org.apache.hc.core5.http.HttpEntity;
1010
import org.apache.hc.core5.http.io.entity.EntityUtils;
1111
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
1212
import org.apache.hc.core5.util.Timeout;
@@ -92,7 +92,14 @@ public ClientResponse execute(REQUEST_TYPES requestType, String url, String data
9292

9393
return client.execute(
9494
request,
95-
response -> new ClientResponse(response.getCode(), EntityUtils.toString(response.getEntity())));
95+
response -> {
96+
final HttpEntity entity = response.getEntity();
97+
int code = response.getCode();
98+
String body = EntityUtils.toString(response.getEntity());
99+
EntityUtils.consume(entity);
100+
101+
return new ClientResponse(code, body);
102+
});
96103
}
97104

98105
/**

0 commit comments

Comments
 (0)