From b5f0c5387f7a98875f60fdf09c8dbe56e5c2766d Mon Sep 17 00:00:00 2001 From: adamw Date: Mon, 24 Jul 2017 17:01:20 +0200 Subject: Closing the async http client if created by sttp --- .../sttp/asynchttpclient/AsyncHttpClientHandler.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'async-http-client-handler/src') diff --git a/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala b/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala index f89c85a..1e924a0 100644 --- a/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala +++ b/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala @@ -30,7 +30,8 @@ import scala.language.higherKinds abstract class AsyncHttpClientHandler[R[_], S]( asyncHttpClient: AsyncHttpClient, - rm: MonadAsyncError[R]) + rm: MonadAsyncError[R], + closeClient: Boolean) extends SttpHandler[R, S] { override def send[T](r: Request[T, S]): R[Response[T]] = { @@ -216,6 +217,11 @@ abstract class AsyncHttpClientHandler[R[_], S]( "Requested a streaming response, trying to read eagerly.")) } } + + def close(): Unit = { + if (closeClient) + asyncHttpClient.close() + } } trait MonadAsyncError[R[_]] { -- cgit v1.2.3