From 60023d319d380c91eb9c355d95316b7f154a624c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Nie=C3=9Fing?= Date: Wed, 30 Mar 2022 19:44:34 +0200 Subject: [PATCH] Issue #4897 - Support for Apache HTTP Client 5.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port fix from #4969 to HttpClient 5.x Signed-off-by: Steffen Nießing --- .../connector/Apache5ConnectionClosingStrategy.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/connectors/apache5-connector/src/main/java/org/glassfish/jersey/apache5/connector/Apache5ConnectionClosingStrategy.java b/connectors/apache5-connector/src/main/java/org/glassfish/jersey/apache5/connector/Apache5ConnectionClosingStrategy.java index 270d21c416..ad23f2d53f 100644 --- a/connectors/apache5-connector/src/main/java/org/glassfish/jersey/apache5/connector/Apache5ConnectionClosingStrategy.java +++ b/connectors/apache5-connector/src/main/java/org/glassfish/jersey/apache5/connector/Apache5ConnectionClosingStrategy.java @@ -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 @@ -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 {