From 827d3147526f24518e2acab58899500e060ff7fa Mon Sep 17 00:00:00 2001 From: Kamil Kloch Date: Mon, 14 Nov 2022 11:31:43 +0100 Subject: [PATCH] Add HttpClientFs2Backend.resourceUsingClient (CE2), add HttpClientMonixBackend.resourceUsingClient. --- .../client3/httpclient/fs2/HttpClientFs2Backend.scala | 10 ++++++++++ .../httpclient/monix/HttpClientMonixBackend.scala | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/effects/fs2-ce2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala b/effects/fs2-ce2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala index 9632edc14c..60abb68bf9 100644 --- a/effects/fs2-ce2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala +++ b/effects/fs2-ce2/src/main/scalajvm/sttp/client3/httpclient/fs2/HttpClientFs2Backend.scala @@ -128,6 +128,16 @@ object HttpClientFs2Backend { ): Resource[F, SttpBackend[F, Fs2Streams[F] with WebSockets]] = Resource.make(apply(blocker, options, customizeRequest, customEncodingHandler))(_.close()) + def resourceUsingClient[F[_]: ConcurrentEffect: ContextShift]( + client: HttpClient, + blocker: Blocker, + customizeRequest: HttpRequest => HttpRequest = identity, + customEncodingHandler: Fs2EncodingHandler[F] = PartialFunction.empty + ): Resource[F, SttpBackend[F, Fs2Streams[F] with WebSockets]] = + Resource.make( + Sync[F].delay(HttpClientFs2Backend(client, blocker, closeClient = true, customizeRequest, customEncodingHandler)) + )(_.close()) + def usingClient[F[_]: ConcurrentEffect: ContextShift]( client: HttpClient, blocker: Blocker, diff --git a/effects/monix/src/main/scalajvm/sttp/client3/httpclient/monix/HttpClientMonixBackend.scala b/effects/monix/src/main/scalajvm/sttp/client3/httpclient/monix/HttpClientMonixBackend.scala index 286e263ef5..2d851bec02 100644 --- a/effects/monix/src/main/scalajvm/sttp/client3/httpclient/monix/HttpClientMonixBackend.scala +++ b/effects/monix/src/main/scalajvm/sttp/client3/httpclient/monix/HttpClientMonixBackend.scala @@ -119,6 +119,17 @@ object HttpClientMonixBackend { ): Resource[Task, SttpBackend[Task, MonixStreams with WebSockets]] = Resource.make(apply(options, customizeRequest, customEncodingHandler))(_.close()) + def resourceUsingClient( + client: HttpClient, + customizeRequest: HttpRequest => HttpRequest = identity, + customEncodingHandler: MonixEncodingHandler = PartialFunction.empty + )(implicit + s: Scheduler = Scheduler.global + ): Resource[Task, SttpBackend[Task, MonixStreams with WebSockets]] = + Resource.make( + Task.eval(HttpClientMonixBackend(client, closeClient = true, customizeRequest, customEncodingHandler)(s)) + )(_.close()) + def usingClient( client: HttpClient, customizeRequest: HttpRequest => HttpRequest = identity,