diff options
author | adamw <adam@warski.org> | 2017-09-14 11:03:21 +0100 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-09-14 11:03:21 +0100 |
commit | fbc71ee712635ed64c50ca694735a84ec794eb11 (patch) | |
tree | bf1dd7335306b7f320262d45d0d5b6d02f5a0b27 | |
parent | a971d409cb1063a2089d936abf3d3ab70bbbabb6 (diff) | |
download | sttp-fbc71ee712635ed64c50ca694735a84ec794eb11.tar.gz sttp-fbc71ee712635ed64c50ca694735a84ec794eb11.tar.bz2 sttp-fbc71ee712635ed64c50ca694735a84ec794eb11.zip |
Renaming "handler" to "backend"
26 files changed, 328 insertions, 325 deletions
@@ -17,7 +17,7 @@ val query = "http language:scala" // `sort` is removed, as the value is not defined val request = sttp.get(uri"https://api.github.com/search/repositories?q=$query&sort=$sort") -implicit val handler = HttpURLConnectionHandler() +implicit val backend = HttpURLConnectionBackend() val response = request.send() // response.header(...): Option[String] @@ -71,7 +71,7 @@ experimenting with sttp by copy-pasting the following: ```scala import $ivy.`com.softwaremill.sttp::core:0.0.13` import com.softwaremill.sttp._ -implicit val handler = HttpURLConnectionHandler() +implicit val backend = HttpURLConnectionBackend() sttp.get(uri"http://httpbin.org/ip").send() ``` @@ -119,11 +119,11 @@ explore the API. And [more will be added](#todo)! You can create a request description without knowing how it will be sent. But to send a request, you will need a backend. A default, synchronous backend based on Java's `HttpURLConnection` is provided out-of-the box. An implicit -value of type `SttpHandler` needs to be in scope to invoke the `send()` on the +value of type `SttpBackend` needs to be in scope to invoke the `send()` on the request: ```scala -implicit val handler = HttpURLConnectionHandler() +implicit val backend = HttpURLConnectionBackend() val response: Response[String] = request.send() ``` @@ -134,8 +134,8 @@ is handled is also part of the request description. The body can be ignore (`.response(asParams)`), mapped (`.mapResponse`) and more; some backends also support request & response streaming. -The default handler doesn't wrap the response into any container, but other -asynchronous handlers might do so. The type parameter in the `Response[_]` +The default backend doesn't wrap the response into any container, but other +asynchronous backends might do so. The type parameter in the `Response[_]` type specifies the type of the body. ## URI interpolator @@ -189,18 +189,18 @@ uri"$scheme://$subdomains.example.com?x=$vx&$params#$jumpTo" ## Starting & cleaning up -In case of most handlers, you should only instantiate a handler once per -application, as a handler typically allocates resources such as thread or +In case of most backends, you should only instantiate a backend once per +application, as a backend typically allocates resources such as thread or connection pools. -When ending the application, make sure to call `handler.close()`, which will +When ending the application, make sure to call `backend.close()`, which will free up resources used by the backend (if any). The close process might be asynchronous, that is it can complete after the `close()` method returns. -Note that only resources allocated by the handlers are freed. For example, -if you use the `AkkaHttpHandler()` the `close()` method will terminate the +Note that only resources allocated by the backends are freed. For example, +if you use the `AkkaHttpBackend()` the `close()` method will terminate the underlying actor system. However, if you have provided an existing actor system -upon handler creation (`AkkaHttpHandler.usingActorSystem`), the `close()` +upon backend creation (`AkkaHttpBackend.usingActorSystem`), the `close()` method will be a no-op. ## Supported backends @@ -209,47 +209,47 @@ method will be a no-op. | Class | Result wrapper | Supported stream type | | --- | --- | --- | -| `HttpURLConnectionHandler` | None (`Id`) | - | -| `AkkaHttpHandler` | `scala.concurrent.Future` | `akka.stream.scaladsl.Source[ByteString, Any]` | -| `AsyncHttpClientFutureHandler` | `scala.concurrent.Future` | - | -| `AsyncHttpClientScalazHandler` | `scalaz.concurrent.Task` | - | -| `AsyncHttpClientMonixHandler` | `monix.eval.Task` | `monix.reactive.Observable[ByteBuffer]` | -| `AsyncHttpClientCatsHandler` | `F[_]: cats.effect.Async` | - | -| `AsyncHttpClientFs2Handler` | `F[_]: cats.effect.Async` | `fs2.Stream[F, ByteBuffer]` | -| `OkHttpSyncHandler` | None (`Id`) | - | -| `OkHttpFutureHandler` | `scala.concurrent.Future` | - | -| `OkHttpMonixHandler` | `monix.eval.Task` | `monix.reactive.Observable[ByteBuffer]` | - -### `HttpURLConnectionHandler` - -The default **synchronous** handler. Sending a request returns a response wrapped +| `HttpURLConnectionBackend` | None (`Id`) | - | +| `AkkaHttpBackend` | `scala.concurrent.Future` | `akka.stream.scaladsl.Source[ByteString, Any]` | +| `AsyncHttpClientFutureBackend` | `scala.concurrent.Future` | - | +| `AsyncHttpClientScalazBackend` | `scalaz.concurrent.Task` | - | +| `AsyncHttpClientMonixBackend` | `monix.eval.Task` | `monix.reactive.Observable[ByteBuffer]` | +| `AsyncHttpClientCatsBackend` | `F[_]: cats.effect.Async` | - | +| `AsyncHttpClientFs2Backend` | `F[_]: cats.effect.Async` | `fs2.Stream[F, ByteBuffer]` | +| `OkHttpSyncBackend` | None (`Id`) | - | +| `OkHttpFutureBackend` | `scala.concurrent.Future` | - | +| `OkHttpMonixBackend` | `monix.eval.Task` | `monix.reactive.Observable[ByteBuffer]` | + +### `HttpURLConnectionBackend` + +The default **synchronous** backend. Sending a request returns a response wrapped in the identity type constructor, which is equivalent to no wrapper at all. To use, add an implicit value: ```scala -implicit val sttpHandler = HttpURLConnectionHandler() +implicit val sttpBackend = HttpURLConnectionBackend() ``` -### `AkkaHttpHandler` +### `AkkaHttpBackend` To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "akka-http-handler" % "0.0.13" +"com.softwaremill.sttp" %% "akka-http-backend" % "0.0.13" ``` -This handler depends on [akka-http](http://doc.akka.io/docs/akka-http/current/scala/http/). -A fully **asynchronous** handler. Sending a request returns a response wrapped +This backend depends on [akka-http](http://doc.akka.io/docs/akka-http/current/scala/http/). +A fully **asynchronous** backend. Sending a request returns a response wrapped in a `Future`. Next you'll need to add an implicit value: ```scala -implicit val sttpHandler = AkkaHttpHandler() +implicit val sttpBackend = AkkaHttpBackend() // or, if you'd like to use an existing actor system: -implicit val sttpHandler = AkkaHttpHandler.usingActorSystem(actorSystem) +implicit val sttpBackend = AkkaHttpBackend.usingActorSystem(actorSystem) ``` This backend supports sending and receiving @@ -281,7 +281,7 @@ import com.softwaremill.sttp.akkahttp._ import akka.stream.scaladsl.Source import akka.util.ByteString -implicit val sttpHandler = AkkaHttpHandler() +implicit val sttpBackend = AkkaHttpBackend() val response: Future[Response[Source[ByteString, Any]]] = sttp @@ -290,22 +290,22 @@ val response: Future[Response[Source[ByteString, Any]]] = .send() ``` -### `AsyncHttpClientHandler` +### `AsyncHttpClientBackend` To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "async-http-client-handler-future" % "0.0.13" +"com.softwaremill.sttp" %% "async-http-client-backend-future" % "0.0.13" // or -"com.softwaremill.sttp" %% "async-http-client-handler-scalaz" % "0.0.13" +"com.softwaremill.sttp" %% "async-http-client-backend-scalaz" % "0.0.13" // or -"com.softwaremill.sttp" %% "async-http-client-handler-monix" % "0.0.13" +"com.softwaremill.sttp" %% "async-http-client-backend-monix" % "0.0.13" // or -"com.softwaremill.sttp" %% "async-http-client-handler-cats" % "0.0.13" +"com.softwaremill.sttp" %% "async-http-client-backend-cats" % "0.0.13" ``` -This handler depends on [async-http-client](https://github.com/AsyncHttpClient/async-http-client). -A fully **asynchronous** handler, which uses [Netty](http://netty.io) behind the +This backend depends on [async-http-client](https://github.com/AsyncHttpClient/async-http-client). +A fully **asynchronous** backend, which uses [Netty](http://netty.io) behind the scenes. The responses are wrapped depending on the dependency chosen in either a: @@ -321,28 +321,28 @@ typeclass, such as `cats.effect.IO`. There's a transitive dependency on `cats-ef Next you'll need to add an implicit value: ```scala -implicit val sttpHandler = AsyncHttpClientFutureHandler() +implicit val sttpBackend = AsyncHttpClientFutureBackend() // or, if you're using the scalaz version: -implicit val sttpHandler = AsyncHttpClientScalazHandler() +implicit val sttpBackend = AsyncHttpClientScalazBackend() // or, if you're using the monix version: -implicit val sttpHandler = AsyncHttpClientMonixHandler() +implicit val sttpBackend = AsyncHttpClientMonixBackend() // or, if you're using the cats effect version: -implicit val sttpHandler = AsyncHttpClientCatsHandler[cats.effect.IO]() +implicit val sttpBackend = AsyncHttpClientCatsBackend[cats.effect.IO]() // or, if you'd like to use custom configuration: -implicit val sttpHandler = AsyncHttpClientFutureHandler.usingConfig(asyncHttpClientConfig) +implicit val sttpBackend = AsyncHttpClientFutureBackend.usingConfig(asyncHttpClientConfig) // or, if you'd like to instantiate the AsyncHttpClient yourself: -implicit val sttpHandler = AsyncHttpClientFutureHandler.usingClient(asyncHttpClient) +implicit val sttpBackend = AsyncHttpClientFutureBackend.usingClient(asyncHttpClient) ``` #### Streaming using Monix -Currently, only the Monix handler supports streaming (as both Monix and Async -Http Client support reactive streams `Publisher`s out of the box). The type of +The Monix backend supports streaming (as both Monix and Async Http Client +support reactive streams `Publisher`s out of the box). The type of supported streams in this case is `Observable[ByteBuffer]`. That is, you can set such an observable as a request body: @@ -369,7 +369,7 @@ import java.nio.ByteBuffer import monix.eval.Task import monix.reactive.Observable -implicit val sttpHandler = AsyncHttpClientMonixHandler() +implicit val sttpBackend = AsyncHttpClientMonixBackend() val response: Task[Response[Observable[ByteBuffer]]] = sttp @@ -378,21 +378,24 @@ val response: Task[Response[Observable[ByteBuffer]]] = .send() ``` -### `OkHttpClientHandler` +It's also possible to use [fs2](https://github.com/functional-streams-for-scala/fs2)s +streams for sending request & receiving responses. + +### `OkHttpClientBackend` To use, add the following dependency to your project: ```scala -"com.softwaremill.sttp" %% "okhttp-handler" % "0.0.13" +"com.softwaremill.sttp" %% "okhttp-backend" % "0.0.13" // or, for the monix version: -"com.softwaremill.sttp" %% "okhttp-handler-monix" % "0.0.13" +"com.softwaremill.sttp" %% "okhttp-backend-monix" % "0.0.13" ``` -This handler depends on [OkHttp](http://square.github.io/okhttp/), and offers: +This backend depends on [OkHttp](http://square.github.io/okhttp/), and offers: -* a **synchronous** handler: `OkHttpSyncHandler` -* an **asynchronous**, `Future`-based handler: `OkHttpFutureHandler` -* an **asynchronous**, Monix-`Task`-based handler: `OkHttpMonixHandler` +* a **synchronous** backend: `OkHttpSyncBackend` +* an **asynchronous**, `Future`-based backend: `OkHttpFutureBackend` +* an **asynchronous**, Monix-`Task`-based backend: `OkHttpMonixBackend` OkHttp fully supports HTTP/2. @@ -431,7 +434,7 @@ a request to decode the response to a specific object. import com.softwaremill.sttp._ import com.softwaremill.sttp.circe._ -implicit val handler = HttpURLConnectionHandler() +implicit val backend = HttpURLConnectionBackend() // Assume that there is an implicit circe encoder in scope // for the request Payload, and a decoder for the Response @@ -487,7 +490,7 @@ import com.softwaremill.sttp._ import scala.concurrent.duration._ // all backends provide a constructor that allows users to specify connection timeout -implicit val handler = HttpURLConnectionHandler(connectionTimeout = 1.minute) +implicit val backend = HttpURLConnectionBackend(connectionTimeout = 1.minute) sttp .get(uri"...") diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala b/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala index c6b0a2c..57b5441 100644 --- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpHandler.scala +++ b/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala @@ -25,11 +25,11 @@ import scala.concurrent.duration.FiniteDuration import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success, Try} -class AkkaHttpHandler private (actorSystem: ActorSystem, +class AkkaHttpBackend private (actorSystem: ActorSystem, ec: ExecutionContext, terminateActorSystemOnClose: Boolean, connectionTimeout: FiniteDuration) - extends SttpHandler[Future, Source[ByteString, Any]] { + extends SttpBackend[Future, Source[ByteString, Any]] { // the supported stream type private type S = Source[ByteString, Any] @@ -281,15 +281,15 @@ class AkkaHttpHandler private (actorSystem: ActorSystem, } } -object AkkaHttpHandler { +object AkkaHttpBackend { private def apply(actorSystem: ActorSystem, ec: ExecutionContext, terminateActorSystemOnClose: Boolean, connectionTimeout: FiniteDuration) - : SttpHandler[Future, Source[ByteString, Any]] = - new FollowRedirectsHandler( - new AkkaHttpHandler(actorSystem, + : SttpBackend[Future, Source[ByteString, Any]] = + new FollowRedirectsBackend( + new AkkaHttpBackend(actorSystem, ec, terminateActorSystemOnClose, connectionTimeout)) @@ -300,10 +300,10 @@ object AkkaHttpHandler { * context. */ def apply(connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Source[ByteString, Any]] = - AkkaHttpHandler(ActorSystem("sttp"), + : SttpBackend[Future, Source[ByteString, Any]] = + AkkaHttpBackend(ActorSystem("sttp"), ec, terminateActorSystemOnClose = true, connectionTimeout) @@ -317,10 +317,10 @@ object AkkaHttpHandler { */ def usingActorSystem(actorSystem: ActorSystem, connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Source[ByteString, Any]] = - AkkaHttpHandler(actorSystem, + : SttpBackend[Future, Source[ByteString, Any]] = + AkkaHttpBackend(actorSystem, ec, terminateActorSystemOnClose = false, connectionTimeout) diff --git a/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala b/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala index fd4d88d..b5beb75 100644 --- a/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala +++ b/async-http-client-backend/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsBackend.scala @@ -3,11 +3,11 @@ package com.softwaremill.sttp.asynchttpclient.cats import java.nio.ByteBuffer import cats.effect._ -import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler +import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend import com.softwaremill.sttp.{ - FollowRedirectsHandler, + FollowRedirectsBackend, MonadAsyncError, - SttpHandler + SttpBackend } import org.asynchttpclient.{ AsyncHttpClient, @@ -19,10 +19,10 @@ import org.reactivestreams.Publisher import scala.concurrent.duration.FiniteDuration import scala.language.higherKinds -class AsyncHttpClientCatsHandler[F[_]: Async] private ( +class AsyncHttpClientCatsBackend[F[_]: Async] private ( asyncHttpClient: AsyncHttpClient, closeClient: Boolean -) extends AsyncHttpClientHandler[F, Nothing]( +) extends AsyncHttpClientBackend[F, Nothing]( asyncHttpClient, new AsyncMonad, closeClient @@ -32,36 +32,36 @@ class AsyncHttpClientCatsHandler[F[_]: Async] private ( override protected def publisherToStreamBody( p: Publisher[ByteBuffer]): Nothing = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") override protected def publisherToString( p: Publisher[ByteBuffer]): F[String] = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") } -object AsyncHttpClientCatsHandler { +object AsyncHttpClientCatsBackend { private def apply[F[_]: Async]( asyncHttpClient: AsyncHttpClient, - closeClient: Boolean): SttpHandler[F, Nothing] = - new FollowRedirectsHandler[F, Nothing]( - new AsyncHttpClientCatsHandler(asyncHttpClient, closeClient)) + closeClient: Boolean): SttpBackend[F, Nothing] = + new FollowRedirectsBackend[F, Nothing]( + new AsyncHttpClientCatsBackend(asyncHttpClient, closeClient)) def apply[F[_]: Async]( - connectionTimeout: FiniteDuration = SttpHandler.DefaultConnectionTimeout) - : SttpHandler[F, Nothing] = - AsyncHttpClientCatsHandler( - AsyncHttpClientHandler.defaultClient(connectionTimeout.toMillis.toInt), + connectionTimeout: FiniteDuration = SttpBackend.DefaultConnectionTimeout) + : SttpBackend[F, Nothing] = + AsyncHttpClientCatsBackend( + AsyncHttpClientBackend.defaultClient(connectionTimeout.toMillis.toInt), closeClient = true) def usingConfig[F[_]: Async]( - cfg: AsyncHttpClientConfig): SttpHandler[F, Nothing] = - AsyncHttpClientCatsHandler(new DefaultAsyncHttpClient(cfg), + cfg: AsyncHttpClientConfig): SttpBackend[F, Nothing] = + AsyncHttpClientCatsBackend(new DefaultAsyncHttpClient(cfg), closeClient = true) def usingClient[F[_]: Async]( - client: AsyncHttpClient): SttpHandler[F, Nothing] = - AsyncHttpClientCatsHandler(client, closeClient = false) + client: AsyncHttpClient): SttpBackend[F, Nothing] = + AsyncHttpClientCatsBackend(client, closeClient = false) } private[cats] class AsyncMonad[F[_]](implicit F: Async[F]) diff --git a/async-http-client-handler/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Handler.scala b/async-http-client-backend/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Backend.scala index 1462951..90db69c 100644 --- a/async-http-client-handler/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Handler.scala +++ b/async-http-client-backend/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Backend.scala @@ -3,11 +3,11 @@ package com.softwaremill.sttp.asynchttpclient.fs2 import java.nio.ByteBuffer import cats.effect._ -import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler +import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend import com.softwaremill.sttp.{ - FollowRedirectsHandler, + FollowRedirectsBackend, MonadAsyncError, - SttpHandler, + SttpBackend, Utf8, concatByteBuffers } @@ -24,10 +24,10 @@ import scala.concurrent.ExecutionContext import scala.concurrent.duration.FiniteDuration import scala.language.higherKinds -class AsyncHttpClientFs2Handler[F[_]: Effect] private ( +class AsyncHttpClientFs2Backend[F[_]: Effect] private ( asyncHttpClient: AsyncHttpClient, closeClient: Boolean)(implicit ec: ExecutionContext) - extends AsyncHttpClientHandler[F, Stream[F, ByteBuffer]]( + extends AsyncHttpClientBackend[F, Stream[F, ByteBuffer]]( asyncHttpClient, new EffectMonad, closeClient @@ -51,13 +51,13 @@ class AsyncHttpClientFs2Handler[F[_]: Effect] private ( } } -object AsyncHttpClientFs2Handler { +object AsyncHttpClientFs2Backend { private def apply[F[_]: Effect](asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( - implicit ec: ExecutionContext): SttpHandler[F, Stream[F, ByteBuffer]] = - new FollowRedirectsHandler( - new AsyncHttpClientFs2Handler(asyncHttpClient, closeClient)) + implicit ec: ExecutionContext): SttpBackend[F, Stream[F, ByteBuffer]] = + new FollowRedirectsBackend( + new AsyncHttpClientFs2Backend(asyncHttpClient, closeClient)) /** * @param ec The execution context for running non-network related operations, @@ -65,11 +65,11 @@ object AsyncHttpClientFs2Handler { * context. */ def apply[F[_]: Effect](connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[F, Stream[F, ByteBuffer]] = - AsyncHttpClientFs2Handler[F]( - AsyncHttpClientHandler.defaultClient(connectionTimeout.toMillis.toInt), + : SttpBackend[F, Stream[F, ByteBuffer]] = + AsyncHttpClientFs2Backend[F]( + AsyncHttpClientBackend.defaultClient(connectionTimeout.toMillis.toInt), closeClient = true) /** @@ -79,8 +79,8 @@ object AsyncHttpClientFs2Handler { */ def usingConfig[F[_]: Effect](cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[F, Stream[F, ByteBuffer]] = - AsyncHttpClientFs2Handler[F](new DefaultAsyncHttpClient(cfg), + : SttpBackend[F, Stream[F, ByteBuffer]] = + AsyncHttpClientFs2Backend[F](new DefaultAsyncHttpClient(cfg), closeClient = true) /** @@ -90,8 +90,8 @@ object AsyncHttpClientFs2Handler { */ def usingClient[F[_]: Effect](client: AsyncHttpClient)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[F, Stream[F, ByteBuffer]] = - AsyncHttpClientFs2Handler[F](client, closeClient = false) + : SttpBackend[F, Stream[F, ByteBuffer]] = + AsyncHttpClientFs2Backend[F](client, closeClient = false) } private[fs2] class EffectMonad[F[_]](implicit F: Effect[F]) diff --git a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHandler.scala b/async-http-client-backend/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureBackend.scala index 371b23c..a46ed0d 100644 --- a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHandler.scala +++ b/async-http-client-backend/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureBackend.scala @@ -2,8 +2,8 @@ package com.softwaremill.sttp.asynchttpclient.future import java.nio.ByteBuffer -import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler -import com.softwaremill.sttp.{FollowRedirectsHandler, FutureMonad, SttpHandler} +import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend +import com.softwaremill.sttp.{FollowRedirectsBackend, FutureMonad, SttpBackend} import org.asynchttpclient.{ AsyncHttpClient, AsyncHttpClientConfig, @@ -14,10 +14,10 @@ import org.reactivestreams.Publisher import scala.concurrent.duration.FiniteDuration import scala.concurrent.{ExecutionContext, Future} -class AsyncHttpClientFutureHandler private ( +class AsyncHttpClientFutureBackend private ( asyncHttpClient: AsyncHttpClient, closeClient: Boolean)(implicit ec: ExecutionContext) - extends AsyncHttpClientHandler[Future, Nothing](asyncHttpClient, + extends AsyncHttpClientBackend[Future, Nothing](asyncHttpClient, new FutureMonad, closeClient) { @@ -26,19 +26,19 @@ class AsyncHttpClientFutureHandler private ( override protected def publisherToStreamBody( p: Publisher[ByteBuffer]): Nothing = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") override protected def publisherToString( p: Publisher[ByteBuffer]): Future[String] = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") } -object AsyncHttpClientFutureHandler { +object AsyncHttpClientFutureBackend { private def apply(asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( - implicit ec: ExecutionContext): SttpHandler[Future, Nothing] = - new FollowRedirectsHandler[Future, Nothing]( - new AsyncHttpClientFutureHandler(asyncHttpClient, closeClient)) + implicit ec: ExecutionContext): SttpBackend[Future, Nothing] = + new FollowRedirectsBackend[Future, Nothing]( + new AsyncHttpClientFutureBackend(asyncHttpClient, closeClient)) /** * @param ec The execution context for running non-network related operations, @@ -46,11 +46,11 @@ object AsyncHttpClientFutureHandler { * context. */ def apply(connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Nothing] = - AsyncHttpClientFutureHandler( - AsyncHttpClientHandler.defaultClient(connectionTimeout.toMillis.toInt), + : SttpBackend[Future, Nothing] = + AsyncHttpClientFutureBackend( + AsyncHttpClientBackend.defaultClient(connectionTimeout.toMillis.toInt), closeClient = true) /** @@ -60,8 +60,8 @@ object AsyncHttpClientFutureHandler { */ def usingConfig(cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Nothing] = - AsyncHttpClientFutureHandler(new DefaultAsyncHttpClient(cfg), + : SttpBackend[Future, Nothing] = + AsyncHttpClientFutureBackend(new DefaultAsyncHttpClient(cfg), closeClient = true) /** @@ -71,6 +71,6 @@ object AsyncHttpClientFutureHandler { */ def usingClient(client: AsyncHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Nothing] = - AsyncHttpClientFutureHandler(client, closeClient = false) + : SttpBackend[Future, Nothing] = + AsyncHttpClientFutureBackend(client, closeClient = false) } diff --git a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHandler.scala b/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala index f01725f..c08c244 100644 --- a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHandler.scala +++ b/async-http-client-backend/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixBackend.scala @@ -3,13 +3,13 @@ package com.softwaremill.sttp.asynchttpclient.monix import java.nio.ByteBuffer import com.softwaremill.sttp.{ - FollowRedirectsHandler, + FollowRedirectsBackend, MonadAsyncError, - SttpHandler, + SttpBackend, Utf8, concatByteBuffers } -import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler +import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend import monix.eval.Task import monix.execution.{Cancelable, Scheduler} import monix.reactive.Observable @@ -23,10 +23,10 @@ import org.reactivestreams.Publisher import scala.concurrent.duration.FiniteDuration import scala.util.{Failure, Success} -class AsyncHttpClientMonixHandler private ( +class AsyncHttpClientMonixBackend private ( asyncHttpClient: AsyncHttpClient, closeClient: Boolean)(implicit scheduler: Scheduler) - extends AsyncHttpClientHandler[Task, Observable[ByteBuffer]]( + extends AsyncHttpClientBackend[Task, Observable[ByteBuffer]]( asyncHttpClient, TaskMonad, closeClient) { @@ -50,24 +50,24 @@ class AsyncHttpClientMonixHandler private ( } } -object AsyncHttpClientMonixHandler { +object AsyncHttpClientMonixBackend { private def apply(asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( implicit scheduler: Scheduler) - : SttpHandler[Task, Observable[ByteBuffer]] = - new FollowRedirectsHandler( - new AsyncHttpClientMonixHandler(asyncHttpClient, closeClient)) + : SttpBackend[Task, Observable[ByteBuffer]] = + new FollowRedirectsBackend( + new AsyncHttpClientMonixBackend(asyncHttpClient, closeClient)) /** * @param s The scheduler used for streaming request bodies. Defaults to the * global scheduler. */ def apply(connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit s: Scheduler = Scheduler.Implicits.global) - : SttpHandler[Task, Observable[ByteBuffer]] = - AsyncHttpClientMonixHandler( - AsyncHttpClientHandler.defaultClient(connectionTimeout.toMillis.toInt), + : SttpBackend[Task, Observable[ByteBuffer]] = + AsyncHttpClientMonixBackend( + AsyncHttpClientBackend.defaultClient(connectionTimeout.toMillis.toInt), closeClient = true) /** @@ -76,8 +76,8 @@ object AsyncHttpClientMonixHandler { */ def usingConfig(cfg: AsyncHttpClientConfig)(implicit s: Scheduler = Scheduler.Implicits.global) - : SttpHandler[Task, Observable[ByteBuffer]] = - AsyncHttpClientMonixHandler(new DefaultAsyncHttpClient(cfg), + : SttpBackend[Task, Observable[ByteBuffer]] = + AsyncHttpClientMonixBackend(new DefaultAsyncHttpClient(cfg), closeClient = true) /** @@ -86,8 +86,8 @@ object AsyncHttpClientMonixHandler { */ def usingClient(client: AsyncHttpClient)(implicit s: Scheduler = Scheduler.Implicits.global) - : SttpHandler[Task, Observable[ByteBuffer]] = - AsyncHttpClientMonixHandler(client, closeClient = false) + : SttpBackend[Task, Observable[ByteBuffer]] = + AsyncHttpClientMonixBackend(client, closeClient = false) } private[monix] object TaskMonad extends MonadAsyncError[Task] { diff --git a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHandler.scala b/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala index 2ba00d7..12e217b 100644 --- a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHandler.scala +++ b/async-http-client-backend/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazBackend.scala @@ -3,11 +3,11 @@ package com.softwaremill.sttp.asynchttpclient.scalaz import java.nio.ByteBuffer import com.softwaremill.sttp.{ - FollowRedirectsHandler, + FollowRedirectsBackend, MonadAsyncError, - SttpHandler + SttpBackend } -import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler +import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend import org.asynchttpclient.{ AsyncHttpClient, AsyncHttpClientConfig, @@ -19,9 +19,9 @@ import scala.concurrent.duration.FiniteDuration import scalaz.{-\/, \/-} import scalaz.concurrent.Task -class AsyncHttpClientScalazHandler private (asyncHttpClient: AsyncHttpClient, +class AsyncHttpClientScalazBackend private (asyncHttpClient: AsyncHttpClient, closeClient: Boolean) - extends AsyncHttpClientHandler[Task, Nothing](asyncHttpClient, + extends AsyncHttpClientBackend[Task, Nothing](asyncHttpClient, TaskMonad, closeClient) { @@ -30,32 +30,32 @@ class AsyncHttpClientScalazHandler private (asyncHttpClient: AsyncHttpClient, override protected def publisherToStreamBody( p: Publisher[ByteBuffer]): Nothing = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") override protected def publisherToString( p: Publisher[ByteBuffer]): Task[String] = - throw new IllegalStateException("This handler does not support streaming") + throw new IllegalStateException("This backend does not support streaming") } -object AsyncHttpClientScalazHandler { +object AsyncHttpClientScalazBackend { private def apply(asyncHttpClient: AsyncHttpClient, - closeClient: Boolean): SttpHandler[Task, Nothing] = - new FollowRedirectsHandler[Task, Nothing]( - new AsyncHttpClientScalazHandler(asyncHttpClient, closeClient)) + closeClient: Boolean): SttpBackend[Task, Nothing] = + new FollowRedirectsBackend[Task, Nothing]( + new AsyncHttpClientScalazBackend(asyncHttpClient, closeClient)) def apply( - connectionTimeout: FiniteDuration = SttpHandler.DefaultConnectionTimeout) - : SttpHandler[Task, Nothing] = - AsyncHttpClientScalazHandler( - AsyncHttpClientHandler.defaultClient(connectionTimeout.toMillis.toInt), + connectionTimeout: FiniteDuration = SttpBackend.DefaultConnectionTimeout) + : SttpBackend[Task, Nothing] = + AsyncHttpClientScalazBackend( + AsyncHttpClientBackend.defaultClient(connectionTimeout.toMillis.toInt), closeClient = true) - def usingConfig(cfg: AsyncHttpClientConfig): SttpHandler[Task, Nothing] = - AsyncHttpClientScalazHandler(new DefaultAsyncHttpClient(cfg), + def usingConfig(cfg: AsyncHttpClientConfig): SttpBackend[Task, Nothing] = + AsyncHttpClientScalazBackend(new DefaultAsyncHttpClient(cfg), closeClient = true) - def usingClient(client: AsyncHttpClient): SttpHandler[Task, Nothing] = - AsyncHttpClientScalazHandler(client, closeClient = false) + def usingClient(client: AsyncHttpClient): SttpBackend[Task, Nothing] = + AsyncHttpClientScalazBackend(client, closeClient = false) } private[scalaz] object TaskMonad extends MonadAsyncError[Task] { diff --git a/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala index 8b6d49c..87a3965 100644 --- a/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala +++ b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala @@ -33,10 +33,10 @@ import scala.collection.JavaConverters._ import scala.language.higherKinds import scala.util.{Failure, Try} -abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, +abstract class AsyncHttpClientBackend[R[_], S](asyncHttpClient: AsyncHttpClient, rm: MonadAsyncError[R], closeClient: Boolean) - extends SttpHandler[R, S] { + extends SttpBackend[R, S] { override def send[T](r: Request[T, S]): R[Response[T]] = { val preparedRequest = asyncHttpClient @@ -112,7 +112,7 @@ abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, override def onBodyPartReceived( bodyPart: HttpResponseBodyPart): AsyncHandler.State = throw new IllegalStateException( - "Requested a streaming handler, unexpected eager body parts.") + "Requested a streaming backend, unexpected eager body parts.") override def onHeadersReceived( headers: HttpResponseHeaders): AsyncHandler.State = { @@ -295,7 +295,7 @@ abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, } } -object AsyncHttpClientHandler { +object AsyncHttpClientBackend { private[asynchttpclient] def defaultClient( connectionTimeout: Int): AsyncHttpClient = @@ -48,15 +48,15 @@ lazy val rootProject = (project in file(".")) .settings(publishArtifact := false, name := "sttp") .aggregate( core, - akkaHttpHandler, - asyncHttpClientHandler, - asyncHttpClientFutureHandler, - asyncHttpClientScalazHandler, - asyncHttpClientMonixHandler, - asyncHttpClientCatsHandler, - asyncHttpClientFs2Handler, - okhttpHandler, - okhttpMonixHandler, + akkaHttpBackend, + asyncHttpClientBackend, + asyncHttpClientFutureBackend, + asyncHttpClientScalazBackend, + asyncHttpClientMonixBackend, + asyncHttpClientCatsBackend, + asyncHttpClientFs2Backend, + okhttpBackend, + okhttpMonixBackend, circe, tests ) @@ -71,85 +71,85 @@ lazy val core: Project = (project in file("core")) ) ) -lazy val akkaHttpHandler: Project = (project in file("akka-http-handler")) +lazy val akkaHttpBackend: Project = (project in file("akka-http-backend")) .settings(commonSettings: _*) .settings( - name := "akka-http-handler", + name := "akka-http-backend", libraryDependencies ++= Seq( akkaHttp ) ) dependsOn core -lazy val asyncHttpClientHandler: Project = (project in file( - "async-http-client-handler")) +lazy val asyncHttpClientBackend: Project = (project in file( + "async-http-client-backend")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler", + name := "async-http-client-backend", libraryDependencies ++= Seq( "org.asynchttpclient" % "async-http-client" % "2.0.35" ) ) dependsOn core -lazy val asyncHttpClientFutureHandler: Project = (project in file( - "async-http-client-handler/future")) +lazy val asyncHttpClientFutureBackend: Project = (project in file( + "async-http-client-backend/future")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler-future" - ) dependsOn asyncHttpClientHandler + name := "async-http-client-backend-future" + ) dependsOn asyncHttpClientBackend -lazy val asyncHttpClientScalazHandler: Project = (project in file( - "async-http-client-handler/scalaz")) +lazy val asyncHttpClientScalazBackend: Project = (project in file( + "async-http-client-backend/scalaz")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler-scalaz", + name := "async-http-client-backend-scalaz", libraryDependencies ++= Seq( "org.scalaz" %% "scalaz-concurrent" % "7.2.14" ) - ) dependsOn asyncHttpClientHandler + ) dependsOn asyncHttpClientBackend -lazy val asyncHttpClientMonixHandler: Project = (project in file( - "async-http-client-handler/monix")) +lazy val asyncHttpClientMonixBackend: Project = (project in file( + "async-http-client-backend/monix")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler-monix", + name := "async-http-client-backend-monix", libraryDependencies ++= Seq(monix) - ) dependsOn asyncHttpClientHandler + ) dependsOn asyncHttpClientBackend -lazy val asyncHttpClientCatsHandler: Project = (project in file( - "async-http-client-handler/cats")) +lazy val asyncHttpClientCatsBackend: Project = (project in file( + "async-http-client-backend/cats")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler-cats", + name := "async-http-client-backend-cats", libraryDependencies ++= Seq( "org.typelevel" %% "cats-effect" % "0.4" ) - ) dependsOn asyncHttpClientHandler + ) dependsOn asyncHttpClientBackend -lazy val asyncHttpClientFs2Handler: Project = (project in file( - "async-http-client-handler/fs2")) +lazy val asyncHttpClientFs2Backend: Project = (project in file( + "async-http-client-backend/fs2")) .settings(commonSettings: _*) .settings( - name := "async-http-client-handler-fs2", + name := "async-http-client-backend-fs2", libraryDependencies ++= Seq( "com.github.zainab-ali" %% "fs2-reactive-streams" % "0.2.2" ) - ) dependsOn asyncHttpClientHandler + ) dependsOn asyncHttpClientBackend -lazy val okhttpHandler: Project = (project in file("okhttp-handler")) +lazy val okhttpBackend: Project = (project in file("okhttp-backend")) .settings(commonSettings: _*) .settings( - name := "okhttp-handler", + name := "okhttp-backend", libraryDependencies ++= Seq( "com.squareup.okhttp3" % "okhttp" % "3.9.0" ) ) dependsOn core -lazy val okhttpMonixHandler: Project = (project in file("okhttp-handler/monix")) +lazy val okhttpMonixBackend: Project = (project in file("okhttp-backend/monix")) .settings(commonSettings: _*) .settings( - name := "okhttp-handler-monix", + name := "okhttp-backend-monix", libraryDependencies ++= Seq(monix) - ) dependsOn okhttpHandler + ) dependsOn okhttpBackend lazy val circe: Project = (project in file("circe")) .settings(commonSettings: _*) @@ -175,5 +175,5 @@ lazy val tests: Project = (project in file("tests")) "ch.qos.logback" % "logback-classic" % "1.2.3" ).map(_ % "test"), libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "test" - ) dependsOn (core, akkaHttpHandler, asyncHttpClientFutureHandler, asyncHttpClientScalazHandler, -asyncHttpClientMonixHandler, asyncHttpClientCatsHandler, asyncHttpClientFs2Handler, okhttpMonixHandler) + ) dependsOn (core, akkaHttpBackend, asyncHttpClientFutureBackend, asyncHttpClientScalazBackend, +asyncHttpClientMonixBackend, asyncHttpClientCatsBackend, asyncHttpClientFs2Backend, okhttpMonixBackend) diff --git a/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsHandler.scala b/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala index 6fe9ce9..accd6b5 100644 --- a/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala @@ -3,8 +3,8 @@ package com.softwaremill.sttp import java.net.URI import scala.language.higherKinds -class FollowRedirectsHandler[R[_], S](delegate: SttpHandler[R, S]) - extends SttpHandler[R, S] { +class FollowRedirectsBackend[R[_], S](delegate: SttpBackend[R, S]) + extends SttpBackend[R, S] { def send[T](request: Request[T, S]): R[Response[T]] = { sendWithCounter(request, 0) @@ -31,7 +31,7 @@ class FollowRedirectsHandler[R[_], S](delegate: SttpHandler[R, S]) redirects: Int): R[Response[T]] = { response.header(LocationHeader).fold(responseMonad.unit(response)) { loc => - if (redirects >= FollowRedirectsHandler.MaxRedirects) { + if (redirects >= FollowRedirectsBackend.MaxRedirects) { responseMonad.unit(Response(Left("Too many redirects"), 0, Nil, Nil)) } else { followRedirect(request, response, redirects, loc) @@ -68,6 +68,6 @@ class FollowRedirectsHandler[R[_], S](delegate: SttpHandler[R, S]) override def responseMonad: MonadError[R] = delegate.responseMonad } -object FollowRedirectsHandler { +object FollowRedirectsBackend { private[sttp] val MaxRedirects = 32 } diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala index c482e6d..2dbb13d 100644 --- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala @@ -13,8 +13,8 @@ import scala.io.Source import scala.collection.JavaConverters._ import scala.concurrent.duration.{Duration, FiniteDuration} -class HttpURLConnectionHandler private (connectionTimeout: FiniteDuration) - extends SttpHandler[Id, Nothing] { +class HttpURLConnectionBackend private (connectionTimeout: FiniteDuration) + extends SttpBackend[Id, Nothing] { override def send[T](r: Request[T, Nothing]): Response[T] = { val c = new URL(r.uri.toString).openConnection().asInstanceOf[HttpURLConnection] @@ -24,7 +24,7 @@ class HttpURLConnectionHandler private (connectionTimeout: FiniteDuration) c.setReadTimeout(timeout(r.options.readTimeout)) c.setConnectTimeout(timeout(connectionTimeout)) - // redirects are handled in SttpHandler + // redirects are handled by FollowRedirectsBackend c.setInstanceFollowRedirects(false) if (r.body != NoBody) { @@ -256,11 +256,11 @@ class HttpURLConnectionHandler private (connectionTimeout: FiniteDuration) override def close(): Unit = {} } -object HttpURLConnectionHandler { +object HttpURLConnectionBackend { def apply( - connectionTimeout: FiniteDuration = SttpHandler.DefaultConnectionTimeout) - : SttpHandler[Id, Nothing] = - new FollowRedirectsHandler[Id, Nothing]( - new HttpURLConnectionHandler(connectionTimeout)) + connectionTimeout: FiniteDuration = SttpBackend.DefaultConnectionTimeout) + : SttpBackend[Id, Nothing] = + new FollowRedirectsBackend[Id, Nothing]( + new HttpURLConnectionBackend(connectionTimeout)) } diff --git a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala index 6e76f6f..320efef 100644 --- a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala +++ b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala @@ -16,7 +16,7 @@ import scala.language.higherKinds * client code to consume it. An exception to this are * streaming responses, which need to fully consumed by the * client if such a response type is requested. - * @param tags Request-specific tags which can be used by handlers for + * @param tags Request-specific tags which can be used by backends for * logging, metrics, etc. Not used by default. * @tparam U Specifies if the method & uri are specified. By default can be * either: @@ -233,13 +233,13 @@ case class RequestT[U[_], T, +S]( def tag(k: String): Option[Any] = tags.get(k) - def send[R[_]]()(implicit handler: SttpHandler[R, S], + def send[R[_]]()(implicit backend: SttpBackend[R, S], isIdInRequest: IsIdInRequest[U]): R[Response[T]] = { // we could avoid the asInstanceOf by creating an artificial copy // changing the method & url fields using `isIdInRequest`, but that // would be only to satisfy the type checker, and a needless copy at // runtime. - handler.send(this.asInstanceOf[RequestT[Id, T, S]]) + backend.send(this.asInstanceOf[RequestT[Id, T, S]]) } private def hasContentType: Boolean = diff --git a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala b/core/src/main/scala/com/softwaremill/sttp/SttpBackend.scala index cb03567..6eb312f 100644 --- a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/SttpBackend.scala @@ -5,22 +5,22 @@ import scala.concurrent.duration._ /** * @tparam R The type constructor in which responses are wrapped. E.g. `Id` - * for synchronous handlers, `Future` for asynchronous handlers. - * @tparam S The type of streams that are supported by the handler. `Nothing`, - * if streaming requests/responses is not supported by this handler. + * for synchronous backends, `Future` for asynchronous backends. + * @tparam S The type of streams that are supported by the backend. `Nothing`, + * if streaming requests/responses is not supported by this backend. */ -trait SttpHandler[R[_], -S] { +trait SttpBackend[R[_], -S] { def send[T](request: Request[T, S]): R[Response[T]] def close(): Unit /** * The monad in which the responses are wrapped. Allows writing wrapper - * handlers, which map/flatMap over the return value of [[send]]. + * backends, which map/flatMap over the return value of [[send]]. */ def responseMonad: MonadError[R] } -object SttpHandler { +object SttpBackend { private[sttp] val DefaultConnectionTimeout = 30.seconds } diff --git a/core/src/main/scala/com/softwaremill/sttp/package.scala b/core/src/main/scala/com/softwaremill/sttp/package.scala index a9950be..c1178d9 100644 --- a/core/src/main/scala/com/softwaremill/sttp/package.scala +++ b/core/src/main/scala/com/softwaremill/sttp/package.scala @@ -23,7 +23,7 @@ package object sttp { /** * Provide an implicit value of this type to serialize arbitrary classes into a request body. - * Handlers might also provide special logic for serializer instances which they define (e.g. to handle streaming). + * Backends might also provide special logic for serializer instances which they define (e.g. to handle streaming). */ type BodySerializer[B] = B => BasicRequestBody diff --git a/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala b/okhttp-backend/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixBackend.scala index b4bcbcf..4b24e65 100644 --- a/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala +++ b/okhttp-backend/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixBackend.scala @@ -3,8 +3,8 @@ package com.softwaremill.sttp.okhttp.monix import java.nio.ByteBuffer import java.util.concurrent.ArrayBlockingQueue -import com.softwaremill.sttp.{SttpHandler, _} -import com.softwaremill.sttp.okhttp.{OkHttpAsyncHandler, OkHttpHandler} +import com.softwaremill.sttp.{SttpBackend, _} +import com.softwaremill.sttp.okhttp.{OkHttpAsyncBackend, OkHttpBackend} import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.{Ack, Cancelable, Scheduler} @@ -17,9 +17,9 @@ import scala.concurrent.Future import scala.concurrent.duration.FiniteDuration import scala.util.{Failure, Success, Try} -class OkHttpMonixHandler private (client: OkHttpClient, closeClient: Boolean)( +class OkHttpMonixBackend private (client: OkHttpClient, closeClient: Boolean)( implicit s: Scheduler) - extends OkHttpAsyncHandler[Task, Observable[ByteBuffer]](client, + extends OkHttpAsyncBackend[Task, Observable[ByteBuffer]](client, TaskMonad, closeClient) { @@ -80,23 +80,23 @@ class OkHttpMonixHandler private (client: OkHttpClient, closeClient: Boolean)( } } -object OkHttpMonixHandler { +object OkHttpMonixBackend { private def apply(client: OkHttpClient, closeClient: Boolean)( - implicit s: Scheduler): SttpHandler[Task, Observable[ByteBuffer]] = - new FollowRedirectsHandler(new OkHttpMonixHandler(client, closeClient)(s)) + implicit s: Scheduler): SttpBackend[Task, Observable[ByteBuffer]] = + new FollowRedirectsBackend(new OkHttpMonixBackend(client, closeClient)(s)) def apply(connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit s: Scheduler = Scheduler.Implicits.global) - : SttpHandler[Task, Observable[ByteBuffer]] = - OkHttpMonixHandler(OkHttpHandler.defaultClient(DefaultReadTimeout.toMillis, + : SttpBackend[Task, Observable[ByteBuffer]] = + OkHttpMonixBackend(OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, connectionTimeout.toMillis), closeClient = true)(s) def usingClient(client: OkHttpClient)(implicit s: Scheduler = Scheduler.Implicits.global) - : SttpHandler[Task, Observable[ByteBuffer]] = - OkHttpMonixHandler(client, closeClient = false)(s) + : SttpBackend[Task, Observable[ByteBuffer]] = + OkHttpMonixBackend(client, closeClient = false)(s) } private[monix] object TaskMonad extends MonadAsyncError[Task] { diff --git a/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala index c009fa5..ead1bde 100644 --- a/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala +++ b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala @@ -26,9 +26,9 @@ import scala.concurrent.{ExecutionContext, Future} import scala.language.higherKinds import scala.util.{Failure, Try} -abstract class OkHttpHandler[R[_], S](client: OkHttpClient, +abstract class OkHttpBackend[R[_], S](client: OkHttpClient, closeClient: Boolean) - extends SttpHandler[R, S] { + extends SttpBackend[R, S] { private[okhttp] def convertRequest[T](request: Request[T, S]): OkHttpRequest = { val builder = new OkHttpRequest.Builder() .url(request.uri.toString) @@ -143,7 +143,7 @@ abstract class OkHttpHandler[R[_], S](client: OkHttpClient, } } -object OkHttpHandler { +object OkHttpBackend { private[okhttp] def defaultClient(readTimeout: Long, connectionTimeout: Long): OkHttpClient = @@ -169,11 +169,11 @@ object OkHttpHandler { } } -class OkHttpSyncHandler private (client: OkHttpClient, closeClient: Boolean) - extends OkHttpHandler[Id, Nothing](client, closeClient) { +class OkHttpSyncBackend private (client: OkHttpClient, closeClient: Boolean) + extends OkHttpBackend[Id, Nothing](client, closeClient) { override def send[T](r: Request[T, Nothing]): Response[T] = { val request = convertRequest(r) - val response = OkHttpHandler + val response = OkHttpBackend .updateClientIfCustomReadTimeout(r, client) .newCall(request) .execute() @@ -183,27 +183,27 @@ class OkHttpSyncHandler private (client: OkHttpClient, closeClient: Boolean) override def responseMonad: MonadError[Id] = IdMonad } -object OkHttpSyncHandler { +object OkHttpSyncBackend { private def apply(client: OkHttpClient, - closeClient: Boolean): SttpHandler[Id, Nothing] = - new FollowRedirectsHandler[Id, Nothing]( - new OkHttpSyncHandler(client, closeClient)) + closeClient: Boolean): SttpBackend[Id, Nothing] = + new FollowRedirectsBackend[Id, Nothing]( + new OkHttpSyncBackend(client, closeClient)) def apply( - connectionTimeout: FiniteDuration = SttpHandler.DefaultConnectionTimeout) - : SttpHandler[Id, Nothing] = - OkHttpSyncHandler(OkHttpHandler.defaultClient(DefaultReadTimeout.toMillis, + connectionTimeout: FiniteDuration = SttpBackend.DefaultConnectionTimeout) + : SttpBackend[Id, Nothing] = + OkHttpSyncBackend(OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, connectionTimeout.toMillis), closeClient = true) - def usingClient(client: OkHttpClient): SttpHandler[Id, Nothing] = - OkHttpSyncHandler(client, closeClient = false) + def usingClient(client: OkHttpClient): SttpBackend[Id, Nothing] = + OkHttpSyncBackend(client, closeClient = false) } -abstract class OkHttpAsyncHandler[R[_], S](client: OkHttpClient, +abstract class OkHttpAsyncBackend[R[_], S](client: OkHttpClient, rm: MonadAsyncError[R], closeClient: Boolean) - extends OkHttpHandler[R, S](client, closeClient) { + extends OkHttpBackend[R, S](client, closeClient) { override def send[T](r: Request[T, S]): R[Response[T]] = { val request = convertRequest(r) @@ -211,7 +211,7 @@ abstract class OkHttpAsyncHandler[R[_], S](client: OkHttpClient, def success(r: R[Response[T]]) = cb(Right(r)) def error(t: Throwable) = cb(Left(t)) - OkHttpHandler + OkHttpBackend .updateClientIfCustomReadTimeout(r, client) .newCall(request) .enqueue(new Callback { @@ -228,28 +228,28 @@ abstract class OkHttpAsyncHandler[R[_], S](client: OkHttpClient, override def responseMonad: MonadError[R] = rm } -class OkHttpFutureHandler private (client: OkHttpClient, closeClient: Boolean)( +class OkHttpFutureBackend private (client: OkHttpClient, closeClient: Boolean)( implicit ec: ExecutionContext) - extends OkHttpAsyncHandler[Future, Nothing](client, + extends OkHttpAsyncBackend[Future, Nothing](client, new FutureMonad, closeClient) {} -object OkHttpFutureHandler { +object OkHttpFutureBackend { private def apply(client: OkHttpClient, closeClient: Boolean)( - implicit ec: ExecutionContext): SttpHandler[Future, Nothing] = - new FollowRedirectsHandler[Future, Nothing]( - new OkHttpFutureHandler(client, closeClient)) + implicit ec: ExecutionContext): SttpBackend[Future, Nothing] = + new FollowRedirectsBackend[Future, Nothing]( + new OkHttpFutureBackend(client, closeClient)) def apply(connectionTimeout: FiniteDuration = - SttpHandler.DefaultConnectionTimeout)( + SttpBackend.DefaultConnectionTimeout)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Nothing] = - OkHttpFutureHandler(OkHttpHandler.defaultClient(DefaultReadTimeout.toMillis, + : SttpBackend[Future, Nothing] = + OkHttpFutureBackend(OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, connectionTimeout.toMillis), closeClient = true) def usingClient(client: OkHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) - : SttpHandler[Future, Nothing] = - OkHttpFutureHandler(client, closeClient = false) + : SttpBackend[Future, Nothing] = + OkHttpFutureBackend(client, closeClient = false) } diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index f544750..de033df 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -14,13 +14,13 @@ import akka.http.scaladsl.server.Route import akka.http.scaladsl.server.directives.Credentials import akka.util.ByteString import better.files._ -import com.softwaremill.sttp.akkahttp.AkkaHttpHandler -import com.softwaremill.sttp.asynchttpclient.cats.AsyncHttpClientCatsHandler -import com.softwaremill.sttp.asynchttpclient.future.AsyncHttpClientFutureHandler -import com.softwaremill.sttp.asynchttpclient.monix.AsyncHttpClientMonixHandler -import com.softwaremill.sttp.asynchttpclient.scalaz.AsyncHttpClientScalazHandler -import com.softwaremill.sttp.okhttp.monix.OkHttpMonixHandler -import com.softwaremill.sttp.okhttp.{OkHttpFutureHandler, OkHttpSyncHandler} +import com.softwaremill.sttp.akkahttp.AkkaHttpBackend +import com.softwaremill.sttp.asynchttpclient.cats.AsyncHttpClientCatsBackend +import com.softwaremill.sttp.asynchttpclient.future.AsyncHttpClientFutureBackend +import com.softwaremill.sttp.asynchttpclient.monix.AsyncHttpClientMonixBackend +import com.softwaremill.sttp.asynchttpclient.scalaz.AsyncHttpClientScalazBackend +import com.softwaremill.sttp.okhttp.monix.OkHttpMonixBackend +import com.softwaremill.sttp.okhttp.{OkHttpFutureBackend, OkHttpSyncBackend} import com.typesafe.scalalogging.StrictLogging import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures} import org.scalatest.{path => _, _} @@ -174,32 +174,32 @@ class BasicTests override def port = 51823 - var closeHandlers: List[() => Unit] = Nil + var closeBackends: List[() => Unit] = Nil - runTests("HttpURLConnection")(HttpURLConnectionHandler(), + runTests("HttpURLConnection")(HttpURLConnectionBackend(), ForceWrappedValue.id) - runTests("Akka HTTP")(AkkaHttpHandler.usingActorSystem(actorSystem), + runTests("Akka HTTP")(AkkaHttpBackend.usingActorSystem(actorSystem), ForceWrappedValue.future) - runTests("Async Http Client - Future")(AsyncHttpClientFutureHandler(), + runTests("Async Http Client - Future")(AsyncHttpClientFutureBackend(), ForceWrappedValue.future) - runTests("Async Http Client - Scalaz")(AsyncHttpClientScalazHandler(), + runTests("Async Http Client - Scalaz")(AsyncHttpClientScalazBackend(), ForceWrappedValue.scalazTask) - runTests("Async Http Client - Monix")(AsyncHttpClientMonixHandler(), + runTests("Async Http Client - Monix")(AsyncHttpClientMonixBackend(), ForceWrappedValue.monixTask) runTests("Async Http Client - Cats Effect")( - AsyncHttpClientCatsHandler[cats.effect.IO](), + AsyncHttpClientCatsBackend[cats.effect.IO](), ForceWrappedValue.catsIo) - runTests("OkHttpSyncClientHandler")(OkHttpSyncHandler(), ForceWrappedValue.id) - runTests("OkHttpAsyncClientHandler - Future")(OkHttpFutureHandler(), + runTests("OkHttpSyncClientHandler")(OkHttpSyncBackend(), ForceWrappedValue.id) + runTests("OkHttpAsyncClientHandler - Future")(OkHttpFutureBackend(), ForceWrappedValue.future) - runTests("OkHttpAsyncClientHandler - Monix")(OkHttpMonixHandler(), + runTests("OkHttpAsyncClientHandler - Monix")(OkHttpMonixBackend(), ForceWrappedValue.monixTask) def runTests[R[_]](name: String)( - implicit handler: SttpHandler[R, Nothing], + implicit backend: SttpBackend[R, Nothing], forceResponse: ForceWrappedValue[R]): Unit = { - closeHandlers = handler.close _ :: closeHandlers + closeBackends = backend.close _ :: closeBackends val postEcho = sttp.post(uri"$endpoint/echo") val testBody = "this is the body" @@ -639,7 +639,7 @@ class BasicTests name should "break redirect loops" in { val resp = loop.send().force() resp.code should be(0) - resp.history should have size (FollowRedirectsHandler.MaxRedirects) + resp.history should have size (FollowRedirectsBackend.MaxRedirects) } } @@ -667,7 +667,7 @@ class BasicTests } override protected def afterAll(): Unit = { - closeHandlers.foreach(_()) + closeBackends.foreach(_()) super.afterAll() } } diff --git a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala index 53ea798..66d040c 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala @@ -5,27 +5,27 @@ import org.scalatest.{FlatSpec, Matchers} import scala.tools.reflect.ToolBoxError class IllTypedTests extends FlatSpec with Matchers { - "compilation" should "fail when trying to stream using the default handler" in { + "compilation" should "fail when trying to stream using the default backend" in { val thrown = intercept[ToolBoxError] { EvalScala( """ import com.softwaremill.sttp._ import akka.stream.scaladsl.Source import akka.util.ByteString - implicit val sttpHandler = HttpURLConnectionHandler + implicit val sttpBackend = HttpURLConnectionBackend() sttp.get(uri"http://example.com").response(asStream[Source[ByteString, Any]]).send() """) } thrown.getMessage should include( - "could not find implicit value for parameter handler: com.softwaremill.sttp.SttpHandler[R,akka.stream.scaladsl.Source[akka.util.ByteString,Any]]") + "could not find implicit value for parameter backend: com.softwaremill.sttp.SttpBackend[R,akka.stream.scaladsl.Source[akka.util.ByteString,Any]]") } "compilation" should "fail when trying to send a request without giving an URL" in { val thrown = intercept[ToolBoxError] { EvalScala(""" import com.softwaremill.sttp._ - implicit val sttpHandler = HttpURLConnectionHandler() + implicit val sttpBackend = HttpURLConnectionBackend() sttp.send() """) } diff --git a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala index 1f6b78c..018c3ab 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala @@ -31,7 +31,7 @@ class StreamingTests val body = "streaming test" - var closeHandlers: List[() => Unit] = Nil + var closeBackends: List[() => Unit] = Nil runTests("Akka Http", new AkkaHttpStreamingTests(actorSystem)) runTests("Monix Async Http Client", new AsyncHttpClientMonixStreamingTests) @@ -40,10 +40,10 @@ class StreamingTests def runTests[R[_], S]( name: String, - testStreamingHandler: TestStreamingHandler[R, S]): Unit = { - import testStreamingHandler._ + testStreamingBackend: TestStreamingBackend[R, S]): Unit = { + import testStreamingBackend._ - closeHandlers = handler.close _ :: closeHandlers + closeBackends = backend.close _ :: closeBackends name should "stream request body" in { val response = sttp @@ -81,7 +81,7 @@ class StreamingTests } override protected def afterAll(): Unit = { - closeHandlers.foreach(_()) + closeBackends.foreach(_()) super.afterAll() } diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala index 25a8d6e..3fca682 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala @@ -5,17 +5,17 @@ import akka.actor.ActorSystem import akka.stream.Materializer import akka.stream.scaladsl.Source import akka.util.ByteString -import com.softwaremill.sttp.akkahttp.AkkaHttpHandler -import com.softwaremill.sttp.{ForceWrappedValue, SttpHandler} +import com.softwaremill.sttp.akkahttp.AkkaHttpBackend +import com.softwaremill.sttp.{ForceWrappedValue, SttpBackend} import scala.concurrent.Future class AkkaHttpStreamingTests(actorSystem: ActorSystem)( implicit materializer: Materializer) - extends TestStreamingHandler[Future, Source[ByteString, Any]] { + extends TestStreamingBackend[Future, Source[ByteString, Any]] { - override implicit val handler: SttpHandler[Future, Source[ByteString, Any]] = - AkkaHttpHandler.usingActorSystem(actorSystem) + override implicit val backend: SttpBackend[Future, Source[ByteString, Any]] = + AkkaHttpBackend.usingActorSystem(actorSystem) override implicit val forceResponse: ForceWrappedValue[Future] = ForceWrappedValue.future diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientFs2StreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientFs2StreamingTests.scala index b55d104..735a5c3 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientFs2StreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientFs2StreamingTests.scala @@ -4,15 +4,15 @@ import java.nio.ByteBuffer import cats.effect._ import cats.implicits._ -import com.softwaremill.sttp.asynchttpclient.fs2.AsyncHttpClientFs2Handler -import com.softwaremill.sttp.{ForceWrappedValue, SttpHandler} +import com.softwaremill.sttp.asynchttpclient.fs2.AsyncHttpClientFs2Backend +import com.softwaremill.sttp.{ForceWrappedValue, SttpBackend} import fs2._ class AsyncHttpClientFs2StreamingTests - extends TestStreamingHandler[IO, Stream[IO, ByteBuffer]] { + extends TestStreamingBackend[IO, Stream[IO, ByteBuffer]] { - override implicit val handler: SttpHandler[IO, Stream[IO, ByteBuffer]] = - AsyncHttpClientFs2Handler[IO]() + override implicit val backend: SttpBackend[IO, Stream[IO, ByteBuffer]] = + AsyncHttpClientFs2Backend[IO]() override implicit val forceResponse: ForceWrappedValue[IO] = ForceWrappedValue.catsIo diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientMonixStreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientMonixStreamingTests.scala index a76aa26..0357668 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientMonixStreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/AsyncHttpClientMonixStreamingTests.scala @@ -2,16 +2,16 @@ package com.softwaremill.sttp.streaming import java.nio.ByteBuffer -import com.softwaremill.sttp.SttpHandler -import com.softwaremill.sttp.asynchttpclient.monix.AsyncHttpClientMonixHandler +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.asynchttpclient.monix.AsyncHttpClientMonixBackend import monix.eval.Task import monix.reactive.Observable -class AsyncHttpClientMonixStreamingTests extends MonixBaseHandler { +class AsyncHttpClientMonixStreamingTests extends MonixBaseBackend { import monix.execution.Scheduler.Implicits.global - override implicit val handler: SttpHandler[Task, Observable[ByteBuffer]] = - AsyncHttpClientMonixHandler() + override implicit val backend: SttpBackend[Task, Observable[ByteBuffer]] = + AsyncHttpClientMonixBackend() } diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/MonixBaseHandler.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/MonixBaseBackend.scala index b34a4ae..3510fbc 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/MonixBaseHandler.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/MonixBaseBackend.scala @@ -6,8 +6,8 @@ import com.softwaremill.sttp.ForceWrappedValue import monix.eval.Task import monix.reactive.Observable -trait MonixBaseHandler - extends TestStreamingHandler[Task, Observable[ByteBuffer]] { +trait MonixBaseBackend + extends TestStreamingBackend[Task, Observable[ByteBuffer]] { override implicit def forceResponse: ForceWrappedValue[Task] = ForceWrappedValue.monixTask diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/OkHttpMonixStreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/OkHttpMonixStreamingTests.scala index 2ea1322..9bfcc26 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/OkHttpMonixStreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/OkHttpMonixStreamingTests.scala @@ -2,16 +2,16 @@ package com.softwaremill.sttp.streaming import java.nio.ByteBuffer -import com.softwaremill.sttp.SttpHandler -import com.softwaremill.sttp.okhttp.monix.OkHttpMonixHandler +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.okhttp.monix.OkHttpMonixBackend import monix.eval.Task import monix.reactive.Observable -class OkHttpMonixStreamingTests extends MonixBaseHandler { +class OkHttpMonixStreamingTests extends MonixBaseBackend { import monix.execution.Scheduler.Implicits.global - override implicit val handler: SttpHandler[Task, Observable[ByteBuffer]] = - OkHttpMonixHandler() + override implicit val backend: SttpBackend[Task, Observable[ByteBuffer]] = + OkHttpMonixBackend() } diff --git a/tests/src/test/scala/com/softwaremill/sttp/streaming/TestStreamingHandler.scala b/tests/src/test/scala/com/softwaremill/sttp/streaming/TestStreamingBackend.scala index b786e49..5fc1c57 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/streaming/TestStreamingHandler.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/streaming/TestStreamingBackend.scala @@ -1,11 +1,11 @@ package com.softwaremill.sttp.streaming -import com.softwaremill.sttp.{ForceWrappedValue, SttpHandler} +import com.softwaremill.sttp.{ForceWrappedValue, SttpBackend} import scala.language.higherKinds -trait TestStreamingHandler[R[_], S] { - implicit def handler: SttpHandler[R, S] +trait TestStreamingBackend[R[_], S] { + implicit def backend: SttpBackend[R, S] implicit def forceResponse: ForceWrappedValue[R] diff --git a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala index 7e4d5a9..4eea904 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala @@ -73,7 +73,7 @@ object ForceWrappedValue extends ScalaFutures with TestingPatience { try { wrapped.runAsync.futureValue } catch { - case e: TestFailedException => throw e.getCause + case e: TestFailedException if e.getCause != null => throw e.getCause } } val catsIo = new ForceWrappedValue[cats.effect.IO] { |