From 618b130e33847d9b8db2c52a454872fe4a9c70a1 Mon Sep 17 00:00:00 2001 From: Kamil Kloch Date: Tue, 8 Nov 2022 15:24:05 +0100 Subject: [PATCH] Add HttpClientFs2Backend.resourceUsingClient. --- .../client3/httpclient/fs2/HttpClientFs2Backend.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/effects/fs2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala b/effects/fs2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala index 139b5e885b..e18ed01f91 100644 --- a/effects/fs2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala +++ b/effects/fs2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala @@ -132,6 +132,17 @@ object HttpClientFs2Backend { Resource.make(apply(dispatcher, options, customizeRequest, customEncodingHandler))(_.close()) ) + def resourceUsingClient[F[_]: Async]( + client: HttpClient, + customizeRequest: HttpRequest => HttpRequest = identity, + customEncodingHandler: Fs2EncodingHandler[F] = PartialFunction.empty + ): Resource[F, SttpBackend[F, Fs2Streams[F] with WebSockets]] = + Dispatcher[F].flatMap(dispatcher => + Resource.make( + Sync[F].delay(apply(client, closeClient = true, customizeRequest, customEncodingHandler, dispatcher)) + )(_.close()) + ) + def usingClient[F[_]: Async]( client: HttpClient, dispatcher: Dispatcher[F],