Skip to content

Commit

Permalink
Close resources in HttpComponents client connector
Browse files Browse the repository at this point in the history
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 spring-projectsgh-27032
  • Loading branch information
bclozel authored and lxbzmy committed Mar 26, 2022
1 parent 8dadf73 commit f640ea1
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,7 +50,7 @@
* @since 5.3
* @see <a href="https://hc.apache.org/index.html">Apache HttpComponents</a>
*/
public class HttpComponentsClientHttpConnector implements ClientHttpConnector {
public class HttpComponentsClientHttpConnector implements ClientHttpConnector, Closeable {

private final CloseableHttpAsyncClient client;

Expand Down Expand Up @@ -126,6 +128,10 @@ private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request
});
}

@Override
public void close() throws IOException {
this.client.close();
}

private static class MonoFutureCallbackAdapter
implements FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>> {
Expand Down

0 comments on commit f640ea1

Please sign in to comment.