Skip to content

Commit

Permalink
Issue eclipse-ee4j#4897 - Support for Apache HTTP Client 5.x
Browse files Browse the repository at this point in the history
Port fix from eclipse-ee4j#4969 to HttpClient 5.x

Signed-off-by: Steffen Nießing <[email protected]>
  • Loading branch information
zUniQueX committed Mar 30, 2022
1 parent 8c9193f commit 60023d3
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;

/**
* Strategy that defines the way the Apache client releases resources. The client enables closing the content stream
Expand Down Expand Up @@ -57,12 +58,20 @@ void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpRes
* Strategy that aborts Apache HttpRequests for the case of Chunked Stream, closes the stream, and response next.
*/
class Apache5GracefulClosingStrategy implements Apache5ConnectionClosingStrategy {
private static final String UNIX_PROTOCOL = "unix";

static final Apache5GracefulClosingStrategy INSTANCE = new Apache5GracefulClosingStrategy();

@Override
public void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpResponse response, InputStream stream)
throws IOException {
if (response.getEntity() != null && response.getEntity().isChunked()) {
boolean isUnixProtocol = false;
try {
isUnixProtocol = UNIX_PROTOCOL.equals(request.getUri().getScheme());
} catch (URISyntaxException ex) {
// Ignore
}
if (response.getEntity() != null && response.getEntity().isChunked() && !isUnixProtocol) {
request.abort();
}
try {
Expand Down

0 comments on commit 60023d3

Please sign in to comment.