Skip to content

Commit a467934

Browse files
authored
Fix connection reuse when using apache-http-client versions 4.3 and 4.4 (#231)
1 parent 1ce6675 commit a467934

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cloudinary-http43/src/main/java/com/cloudinary/http43/ApiStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.cloudinary.utils.ObjectUtils;
1111
import com.cloudinary.utils.StringUtils;
1212
import org.apache.http.Consts;
13+
import org.apache.http.HttpEntity;
1314
import org.apache.http.HttpHost;
1415
import org.apache.http.client.config.RequestConfig;
1516
import org.apache.http.client.entity.UrlEncodedFormEntity;
@@ -21,6 +22,7 @@
2122
import org.apache.http.impl.client.CloseableHttpClient;
2223
import org.apache.http.impl.client.HttpClientBuilder;
2324
import org.apache.http.impl.client.HttpClients;
25+
import org.apache.http.util.EntityUtils;
2426
import org.cloudinary.json.JSONException;
2527
import org.cloudinary.json.JSONObject;
2628

@@ -98,8 +100,9 @@ private ApiResponse getApiResponse(HttpUriRequest request) throws Exception {
98100
CloseableHttpResponse response = client.execute(request);
99101
try {
100102
code = response.getStatusLine().getStatusCode();
101-
InputStream responseStream = response.getEntity().getContent();
102-
responseData = StringUtils.read(responseStream);
103+
final HttpEntity entity = response.getEntity();
104+
responseData = StringUtils.read(entity.getContent());
105+
EntityUtils.consume(entity);
103106
} finally {
104107
response.close();
105108
}

cloudinary-http44/src/main/java/com/cloudinary/http44/ApiStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.cloudinary.utils.ObjectUtils;
1111
import com.cloudinary.utils.StringUtils;
1212
import org.apache.http.Consts;
13+
import org.apache.http.HttpEntity;
1314
import org.apache.http.HttpHost;
1415
import org.apache.http.NameValuePair;
1516
import org.apache.http.client.config.RequestConfig;
@@ -22,6 +23,7 @@
2223
import org.apache.http.impl.client.CloseableHttpClient;
2324
import org.apache.http.impl.client.HttpClientBuilder;
2425
import org.apache.http.impl.client.HttpClients;
26+
import org.apache.http.util.EntityUtils;
2527
import org.cloudinary.json.JSONException;
2628
import org.cloudinary.json.JSONObject;
2729

@@ -100,8 +102,9 @@ private ApiResponse getApiResponse(HttpUriRequest request) throws Exception {
100102
CloseableHttpResponse response = client.execute(request);
101103
try {
102104
code = response.getStatusLine().getStatusCode();
103-
InputStream responseStream = response.getEntity().getContent();
104-
responseData = StringUtils.read(responseStream);
105+
final HttpEntity entity = response.getEntity();
106+
responseData = StringUtils.read(entity.getContent());
107+
EntityUtils.consume(entity);
105108
} finally {
106109
response.close();
107110
}

0 commit comments

Comments
 (0)