Skip to content

Commit 05eca05

Browse files
committed
Close resources in HttpComponents client connector
Prior to this commit, the `HttpComponentsClientHttpConnector` implementation could accept or create a default `HttpClient` instance but not expose it as part of its API. This effectively prevents applications from properly closing the associated resources when disposing of the connector. This commit implements the `Closeable` interface on the connector to allow this use case. Closes gh-27032
1 parent 3fa4e41 commit 05eca05

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.http.client.reactive;
1818

19+
import java.io.Closeable;
20+
import java.io.IOException;
1921
import java.net.URI;
2022
import java.nio.ByteBuffer;
2123
import java.util.function.BiFunction;
@@ -48,7 +50,7 @@
4850
* @since 5.3
4951
* @see <a href="https://hc.apache.org/index.html">Apache HttpComponents</a>
5052
*/
51-
public class HttpComponentsClientHttpConnector implements ClientHttpConnector {
53+
public class HttpComponentsClientHttpConnector implements ClientHttpConnector, Closeable {
5254

5355
private final CloseableHttpAsyncClient client;
5456

@@ -126,6 +128,10 @@ private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request
126128
});
127129
}
128130

131+
@Override
132+
public void close() throws IOException {
133+
this.client.close();
134+
}
129135

130136
private static class MonoFutureCallbackAdapter
131137
implements FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>> {

0 commit comments

Comments
 (0)