diff options
Diffstat (limited to 'vespa-http-client')
-rw-r--r-- | vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java index bd5cf761024..735ca0beb40 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java @@ -23,6 +23,7 @@ import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicHeader; +import org.apache.http.util.EntityUtils; import javax.net.ssl.SSLContext; import java.io.ByteArrayInputStream; @@ -246,24 +247,21 @@ class ApacheGatewayConnection implements GatewayConnection { } private InputStream executePost(HttpPost httpPost) throws ServerResponseException, IOException { - HttpResponse response; - try { - if (httpClient == null) - throw new IOException("Trying to executePost while not having a connection/http client"); - response = httpClient.execute(httpPost); - } catch (Exception e) { - httpPost.abort(); - throw e; - } + if (httpClient == null) + throw new IOException("Trying to executePost while not having a connection/http client"); + HttpResponse response = httpClient.execute(httpPost); try { verifyServerResponseCode(response); verifyServerVersion(response.getFirstHeader(Headers.VERSION)); verifySessionHeader(response.getFirstHeader(Headers.SESSION_ID)); } catch (ServerResponseException e) { - httpPost.abort(); + // Ensure response is consumed to allow connection reuse later on + EntityUtils.consumeQuietly(response.getEntity()); throw e; } - return response.getEntity().getContent(); + // Consume response now to allow connection to be reused immediately + byte[] responseData = EntityUtils.toByteArray(response.getEntity()); + return responseData == null ? null : new ByteArrayInputStream(responseData); } private void verifyServerResponseCode(HttpResponse response) throws ServerResponseException { |