Skip to content

Commit

Permalink
Merge pull request #1762 from softwaremill/reorganize-backends
Browse files Browse the repository at this point in the history
Categorize backends into packages
  • Loading branch information
adamw authored Mar 13, 2023
2 parents f9ff1b2 + 9e3be1d commit c158735
Show file tree
Hide file tree
Showing 118 changed files with 307 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import sttp.client4
import sttp.client4.akkahttp.AkkaHttpBackend.EncodingHandler
import sttp.client4.testing.WebSocketStreamBackendStub
import sttp.client4._
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.model.{ResponseMetadata, StatusCode}
import sttp.monad.{FutureMonad, MonadError}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.internal.NoStreams
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaCatsBackend[F[_]: Concurrent](client: WebClient, closeFactory: Boolean)
Expand Down Expand Up @@ -61,5 +62,5 @@ object ArmeriaCatsBackend {
client: WebClient,
closeFactory: Boolean
): Backend[F] =
FollowRedirectsBackend(new ArmeriaCatsBackend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaCatsBackend(client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.internal.NoStreams
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaCatsBackend[F[_]: Async](client: WebClient, closeFactory: Boolean)
Expand Down Expand Up @@ -61,5 +62,5 @@ object ArmeriaCatsBackend {
client: WebClient,
closeFactory: Boolean
): Backend[F] =
FollowRedirectsBackend(new ArmeriaCatsBackend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaCatsBackend(client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import sttp.capabilities.fs2.Fs2Streams
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.{FollowRedirectsBackend, StreamBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, StreamBackend, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaFs2Backend[F[_]: ConcurrentEffect](client: WebClient, closeFactory: Boolean)
Expand Down Expand Up @@ -70,5 +71,5 @@ object ArmeriaFs2Backend {
client: WebClient,
closeFactory: Boolean
): StreamBackend[F, Fs2Streams[F]] =
FollowRedirectsBackend(new ArmeriaFs2Backend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaFs2Backend(client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import sttp.capabilities.fs2.Fs2Streams
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.{FollowRedirectsBackend, StreamBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, StreamBackend, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaFs2Backend[F[_]: Async](client: WebClient, closeFactory: Boolean, dispatcher: Dispatcher[F])
Expand Down Expand Up @@ -79,5 +80,5 @@ object ArmeriaFs2Backend {
closeFactory: Boolean,
dispatcher: Dispatcher[F]
): StreamBackend[F, Fs2Streams[F]] =
FollowRedirectsBackend(new ArmeriaFs2Backend(client, closeFactory, dispatcher))
wrappers.FollowRedirectsBackend(new ArmeriaFs2Backend(client, closeFactory, dispatcher))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import sttp.capabilities.monix.MonixStreams
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.monix.TaskMonadAsyncError
import sttp.client4.{FollowRedirectsBackend, StreamBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, StreamBackend, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaMonixBackend(client: WebClient, closeFactory: Boolean)(implicit scheduler: Scheduler)
Expand Down Expand Up @@ -62,5 +63,5 @@ object ArmeriaMonixBackend {
private def apply(client: WebClient, closeFactory: Boolean)(implicit
scheduler: Scheduler
): StreamBackend[Task, MonixStreams] =
FollowRedirectsBackend(new ArmeriaMonixBackend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaMonixBackend(client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.scalaz.TaskMonadAsyncError
import sttp.client4.internal.NoStreams
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.MonadAsyncError

private final class ArmeriaScalazBackend(client: WebClient, closeFactory: Boolean)
Expand Down Expand Up @@ -49,5 +50,5 @@ object ArmeriaScalazBackend {
client: WebClient,
closeFactory: Boolean
): Backend[Task] =
FollowRedirectsBackend(new ArmeriaScalazBackend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaScalazBackend(client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.reactivestreams.Publisher
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.internal.NoStreams
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.{FutureMonad, MonadAsyncError}

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -49,5 +50,5 @@ object ArmeriaFutureBackend {
apply(newClient(), closeFactory = false)

private def apply(client: WebClient, closeFactory: Boolean): Backend[Future] =
FollowRedirectsBackend(new ArmeriaFutureBackend(client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaFutureBackend(client, closeFactory))
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package sttp.client4.armeria.zio

import _root_.zio.interop.reactivestreams.{
publisherToStream => publisherToZioStream,
streamToPublisher => zioStreamToPublisher
}
import _root_.zio.interop.reactivestreams.{publisherToStream => publisherToZioStream, streamToPublisher => zioStreamToPublisher}
import _root_.zio.{Chunk, Task, _}
import com.linecorp.armeria.client.WebClient
import com.linecorp.armeria.common.HttpData
Expand All @@ -13,7 +10,8 @@ import sttp.capabilities.zio.ZioStreams
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.zio.RIOMonadAsyncError
import sttp.client4.{FollowRedirectsBackend, StreamBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, StreamBackend, wrappers}
import sttp.monad.MonadAsyncError
import zio.stream.Stream

Expand Down Expand Up @@ -81,5 +79,5 @@ object ArmeriaZioBackend {
.map(runtime => apply(runtime, newClient(), closeFactory = false))

private def apply[R](runtime: Runtime[R], client: WebClient, closeFactory: Boolean): StreamBackend[Task, ZioStreams] =
FollowRedirectsBackend(new ArmeriaZioBackend(runtime, client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaZioBackend(runtime, client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import org.reactivestreams.Publisher
import sttp.capabilities.zio.ZioStreams
import sttp.client4.armeria.{AbstractArmeriaBackend, BodyFromStreamMessage}
import sttp.client4.impl.zio.RIOMonadAsyncError
import sttp.client4.{FollowRedirectsBackend, StreamBackend, BackendOptions}
import sttp.client4.{BackendOptions, StreamBackend, wrappers}
import sttp.monad.MonadAsyncError
import zio.{Chunk, Task}
import zio.stream.Stream
import _root_.zio._
import _root_.zio.interop.reactivestreams.{
publisherToStream => publisherToZioStream,
streamToPublisher => zioStreamToPublisher
}
import _root_.zio.interop.reactivestreams.{publisherToStream => publisherToZioStream, streamToPublisher => zioStreamToPublisher}
import sttp.client4.armeria.ArmeriaWebClient.newClient
import sttp.client4.wrappers.FollowRedirectsBackend

private final class ArmeriaZioBackend(runtime: Runtime[Any], client: WebClient, closeFactory: Boolean)
extends AbstractArmeriaBackend[Task, ZioStreams](client, closeFactory, new RIOMonadAsyncError[Any]) {
Expand Down Expand Up @@ -69,5 +67,5 @@ object ArmeriaZioBackend {
.map(runtime => apply(runtime, newClient(), closeFactory = false))

private def apply[R](runtime: Runtime[R], client: WebClient, closeFactory: Boolean): StreamBackend[Task, ZioStreams] =
FollowRedirectsBackend(new ArmeriaZioBackend(runtime, client, closeFactory))
wrappers.FollowRedirectsBackend(new ArmeriaZioBackend(runtime, client, closeFactory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@ package sttp.client4.asynchttpclient.cats

import java.io.{ByteArrayInputStream, File}
import java.nio.ByteBuffer

import cats.effect.implicits._
import cats.effect.{Concurrent, ContextShift, Resource, Sync}
import io.netty.buffer.ByteBuf
import org.asynchttpclient.{
AsyncHttpClient,
AsyncHttpClientConfig,
BoundRequestBuilder,
DefaultAsyncHttpClient,
DefaultAsyncHttpClientConfig
}
import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, BoundRequestBuilder, DefaultAsyncHttpClient, DefaultAsyncHttpClientConfig}
import org.reactivestreams.Publisher
import sttp.client4.asynchttpclient.{AsyncHttpClientBackend, BodyFromAHC, BodyToAHC}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.internal.{FileHelpers, NoStreams}
import sttp.client4.{Backend, FollowRedirectsBackend, GenericRequest, Response, BackendOptions}
import sttp.client4.{Backend, BackendOptions, GenericRequest, Response, wrappers}
import cats.implicits._
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.BackendStub
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.monad.MonadAsyncError
import sttp.ws.WebSocket

Expand Down Expand Up @@ -70,7 +64,7 @@ object AsyncHttpClientCatsBackend {
closeClient: Boolean,
customizeRequest: BoundRequestBuilder => BoundRequestBuilder
): Backend[F] =
FollowRedirectsBackend(new AsyncHttpClientCatsBackend(asyncHttpClient, closeClient, customizeRequest))
wrappers.FollowRedirectsBackend(new AsyncHttpClientCatsBackend(asyncHttpClient, closeClient, customizeRequest))

/** After sending a request, always shifts to the thread pool backing the given `ContextShift[F]`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ package sttp.client4.asynchttpclient.cats

import java.io.{ByteArrayInputStream, File}
import java.nio.ByteBuffer

import cats.effect.kernel.{Async, Resource, Sync}
import io.netty.buffer.ByteBuf
import org.asynchttpclient.{
AsyncHttpClient,
AsyncHttpClientConfig,
BoundRequestBuilder,
DefaultAsyncHttpClient,
DefaultAsyncHttpClientConfig
}
import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, BoundRequestBuilder, DefaultAsyncHttpClient, DefaultAsyncHttpClientConfig}
import org.reactivestreams.Publisher
import sttp.client4.asynchttpclient.{AsyncHttpClientBackend, BodyFromAHC, BodyToAHC}
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.internal.{FileHelpers, NoStreams}
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.{Backend, BackendOptions, wrappers}
import cats.implicits._
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.BackendStub
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.monad.MonadAsyncError
import sttp.ws.WebSocket

Expand Down Expand Up @@ -65,7 +59,7 @@ object AsyncHttpClientCatsBackend {
closeClient: Boolean,
customizeRequest: BoundRequestBuilder => BoundRequestBuilder
): Backend[F] =
FollowRedirectsBackend(new AsyncHttpClientCatsBackend(asyncHttpClient, closeClient, customizeRequest))
wrappers.FollowRedirectsBackend(new AsyncHttpClientCatsBackend(asyncHttpClient, closeClient, customizeRequest))

def apply[F[_]: Async](
options: BackendOptions = BackendOptions.Default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import sttp.client4.internal._
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.WebSocketStreamBackendStub
import sttp.client4._
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.monad.MonadAsyncError
import sttp.ws.{WebSocket, WebSocketFrame}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import sttp.client4.impl.fs2.{Fs2SimpleQueue, Fs2WebSockets}
import sttp.client4.internal._
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.WebSocketStreamBackendStub
import sttp.client4.{FollowRedirectsBackend, BackendOptions, WebSocketStreamBackend}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, WebSocketStreamBackend, wrappers}
import sttp.monad.MonadAsyncError
import sttp.ws.{WebSocket, WebSocketFrame}

Expand Down Expand Up @@ -102,7 +103,7 @@ object AsyncHttpClientFs2Backend {
webSocketBufferCapacity: Option[Int],
dispatcher: Dispatcher[F]
): WebSocketStreamBackend[F, Fs2Streams[F]] =
FollowRedirectsBackend(
wrappers.FollowRedirectsBackend(
new AsyncHttpClientFs2Backend(asyncHttpClient, closeClient, customizeRequest, webSocketBufferCapacity, dispatcher)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package sttp.client4.asynchttpclient.future

import java.nio.ByteBuffer

import io.netty.buffer.ByteBuf
import org.asynchttpclient.{
AsyncHttpClient,
AsyncHttpClientConfig,
BoundRequestBuilder,
DefaultAsyncHttpClient,
DefaultAsyncHttpClientConfig
}
import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, BoundRequestBuilder, DefaultAsyncHttpClient, DefaultAsyncHttpClientConfig}
import org.reactivestreams.Publisher
import sttp.client4.asynchttpclient.{AsyncHttpClientBackend, BodyFromAHC, BodyToAHC}
import sttp.client4.internal.NoStreams
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.BackendStub
import sttp.client4.{Backend, FollowRedirectsBackend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.{FutureMonad, MonadAsyncError}
import sttp.ws.WebSocket

Expand Down Expand Up @@ -63,7 +57,7 @@ object AsyncHttpClientFutureBackend {
)(implicit
ec: ExecutionContext
): Backend[Future] =
FollowRedirectsBackend(new AsyncHttpClientFutureBackend(asyncHttpClient, closeClient, customizeRequest))
wrappers.FollowRedirectsBackend(new AsyncHttpClientFutureBackend(asyncHttpClient, closeClient, customizeRequest))

/** @param ec
* The execution context for running non-network related operations, e.g. mapping responses. Defaults to the global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import sttp.client4.impl.monix.{MonixSimpleQueue, MonixWebSockets, TaskMonadAsyn
import sttp.client4.internal._
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.WebSocketStreamBackendStub
import sttp.client4.{FollowRedirectsBackend, BackendOptions, WebSocketStreamBackend}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{BackendOptions, WebSocketStreamBackend, wrappers}
import sttp.monad.MonadAsyncError
import sttp.ws.{WebSocket, WebSocketFrame}

Expand Down Expand Up @@ -95,7 +96,7 @@ object AsyncHttpClientMonixBackend {
)(implicit
scheduler: Scheduler
): WebSocketStreamBackend[Task, MonixStreams] =
FollowRedirectsBackend(
wrappers.FollowRedirectsBackend(
new AsyncHttpClientMonixBackend(asyncHttpClient, closeClient, customizeRequest, webSocketBufferCapacity)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package sttp.client4.asynchttpclient.scalaz

import java.nio.ByteBuffer

import io.netty.buffer.ByteBuf
import org.asynchttpclient.{
AsyncHttpClient,
AsyncHttpClientConfig,
BoundRequestBuilder,
DefaultAsyncHttpClient,
DefaultAsyncHttpClientConfig
}
import org.asynchttpclient.{AsyncHttpClient, AsyncHttpClientConfig, BoundRequestBuilder, DefaultAsyncHttpClient, DefaultAsyncHttpClientConfig}
import org.reactivestreams.Publisher
import scalaz.concurrent.Task
import sttp.client4.asynchttpclient.{AsyncHttpClientBackend, BodyFromAHC, BodyToAHC}
import sttp.client4.impl.scalaz.TaskMonadAsyncError
import sttp.client4.internal.NoStreams
import sttp.client4.internal.ws.SimpleQueue
import sttp.client4.testing.BackendStub
import sttp.client4.{FollowRedirectsBackend, Backend, BackendOptions}
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.{Backend, BackendOptions, wrappers}
import sttp.monad.MonadAsyncError
import sttp.ws.WebSocket

Expand Down Expand Up @@ -58,7 +52,7 @@ object AsyncHttpClientScalazBackend {
closeClient: Boolean,
customizeRequest: BoundRequestBuilder => BoundRequestBuilder
): Backend[Task] =
FollowRedirectsBackend(new AsyncHttpClientScalazBackend(asyncHttpClient, closeClient, customizeRequest))
wrappers.FollowRedirectsBackend(new AsyncHttpClientScalazBackend(asyncHttpClient, closeClient, customizeRequest))

def apply(
options: BackendOptions = BackendOptions.Default,
Expand Down
Loading

0 comments on commit c158735

Please sign in to comment.