From 05eca05671e49c3ec1ca9470cad08d333ea9d996 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 8 Jun 2021 11:22:30 +0200 Subject: [PATCH] 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 --- .../reactive/HttpComponentsClientHttpConnector.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java index 90ed8ff36b..612da6ec34 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java @@ -16,6 +16,8 @@ package org.springframework.http.client.reactive; +import java.io.Closeable; +import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; import java.util.function.BiFunction; @@ -48,7 +50,7 @@ import org.springframework.util.Assert; * @since 5.3 * @see Apache HttpComponents */ -public class HttpComponentsClientHttpConnector implements ClientHttpConnector { +public class HttpComponentsClientHttpConnector implements ClientHttpConnector, Closeable { private final CloseableHttpAsyncClient client; @@ -126,6 +128,10 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector { }); } + @Override + public void close() throws IOException { + this.client.close(); + } private static class MonoFutureCallbackAdapter implements FutureCallback>> {