Skip to content

Commit

Permalink
Add HttpClientFs2Backend.resourceUsingClient (CE2), add HttpClientMon…
Browse files Browse the repository at this point in the history
…ixBackend.resourceUsingClient.
  • Loading branch information
kamilkloch committed Nov 14, 2022
1 parent 8088994 commit 827d314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 827d314

Please sign in to comment.