diff options
author | adamw <adam@warski.org> | 2017-09-04 16:27:43 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-09-04 16:27:43 +0200 |
commit | 2761923dcf1ea49f7671cc2f18df9bd07f0df40b (patch) | |
tree | 1e20c4d823f0ff734d77c54e96ab738f4186c740 /async-http-client-handler | |
parent | 41bbe08c125bb3714aee862ec9dc55419c29986d (diff) | |
download | sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.tar.gz sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.tar.bz2 sttp-2761923dcf1ea49f7671cc2f18df9bd07f0df40b.zip |
Extracting FollowRedirectsHandler as a wrapper-handler
Diffstat (limited to 'async-http-client-handler')
6 files changed, 66 insertions, 29 deletions
diff --git a/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala b/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala index a2c374a..18949c0 100644 --- a/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala +++ b/async-http-client-handler/cats/src/main/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHandler.scala @@ -4,7 +4,11 @@ import java.nio.ByteBuffer import cats.effect._ import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler -import com.softwaremill.sttp.{MonadAsyncError, SttpHandler} +import com.softwaremill.sttp.{ + FollowRedirectsHandler, + MonadAsyncError, + SttpHandler +} import org.asynchttpclient.{ AsyncHttpClient, AsyncHttpClientConfig, @@ -36,18 +40,23 @@ class AsyncHttpClientCatsHandler[F[_]: Async] private ( object AsyncHttpClientCatsHandler { + private def apply[F[_]: Async]( + asyncHttpClient: AsyncHttpClient, + closeClient: Boolean): SttpHandler[F, Nothing] = + new FollowRedirectsHandler[F, Nothing]( + new AsyncHttpClientCatsHandler(asyncHttpClient, closeClient)) + def apply[F[_]: Async](): SttpHandler[F, Nothing] = - new AsyncHttpClientCatsHandler(new DefaultAsyncHttpClient(), - closeClient = true) + AsyncHttpClientCatsHandler(new DefaultAsyncHttpClient(), closeClient = true) def usingConfig[F[_]: Async]( cfg: AsyncHttpClientConfig): SttpHandler[F, Nothing] = - new AsyncHttpClientCatsHandler(new DefaultAsyncHttpClient(cfg), - closeClient = true) + AsyncHttpClientCatsHandler(new DefaultAsyncHttpClient(cfg), + closeClient = true) def usingClient[F[_]: Async]( client: AsyncHttpClient): SttpHandler[F, Nothing] = - new AsyncHttpClientCatsHandler(client, closeClient = false) + AsyncHttpClientCatsHandler(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-handler/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Handler.scala index 1686b25..56e7b8c 100644 --- a/async-http-client-handler/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Handler.scala +++ b/async-http-client-handler/fs2/src/main/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2Handler.scala @@ -5,6 +5,7 @@ import java.nio.ByteBuffer import cats.effect._ import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler import com.softwaremill.sttp.{ + FollowRedirectsHandler, MonadAsyncError, SttpHandler, Utf8, @@ -51,6 +52,12 @@ class AsyncHttpClientFs2Handler[F[_]: Effect] private ( object AsyncHttpClientFs2Handler { + private def apply[F[_]: Effect](asyncHttpClient: AsyncHttpClient, + closeClient: Boolean)( + implicit ec: ExecutionContext): SttpHandler[F, Stream[F, ByteBuffer]] = + new FollowRedirectsHandler( + new AsyncHttpClientFs2Handler(asyncHttpClient, closeClient)) + /** * @param ec The execution context for running non-network related operations, * e.g. mapping responses. Defaults to the global execution @@ -59,8 +66,8 @@ object AsyncHttpClientFs2Handler { def apply[F[_]: Effect]()( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[F, Stream[F, ByteBuffer]] = - new AsyncHttpClientFs2Handler[F](new DefaultAsyncHttpClient(), - closeClient = true) + AsyncHttpClientFs2Handler[F](new DefaultAsyncHttpClient(), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -70,8 +77,8 @@ object AsyncHttpClientFs2Handler { def usingConfig[F[_]: Effect](cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[F, Stream[F, ByteBuffer]] = - new AsyncHttpClientFs2Handler[F](new DefaultAsyncHttpClient(cfg), - closeClient = true) + AsyncHttpClientFs2Handler[F](new DefaultAsyncHttpClient(cfg), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -81,7 +88,7 @@ object AsyncHttpClientFs2Handler { def usingClient[F[_]: Effect](client: AsyncHttpClient)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[F, Stream[F, ByteBuffer]] = - new AsyncHttpClientFs2Handler[F](client, closeClient = false) + AsyncHttpClientFs2Handler[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-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHandler.scala index 81dee9e..b80a91e 100644 --- a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHandler.scala +++ b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHandler.scala @@ -3,7 +3,7 @@ package com.softwaremill.sttp.asynchttpclient.future import java.nio.ByteBuffer import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler -import com.softwaremill.sttp.{FutureMonad, SttpHandler} +import com.softwaremill.sttp.{FollowRedirectsHandler, FutureMonad, SttpHandler} import org.asynchttpclient.{ AsyncHttpClient, AsyncHttpClientConfig, @@ -34,6 +34,11 @@ class AsyncHttpClientFutureHandler private ( object AsyncHttpClientFutureHandler { + private def apply(asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( + implicit ec: ExecutionContext): SttpHandler[Future, Nothing] = + new FollowRedirectsHandler[Future, Nothing]( + new AsyncHttpClientFutureHandler(asyncHttpClient, closeClient)) + /** * @param ec The execution context for running non-network related operations, * e.g. mapping responses. Defaults to the global execution @@ -41,8 +46,8 @@ object AsyncHttpClientFutureHandler { */ def apply()(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Nothing] = - new AsyncHttpClientFutureHandler(new DefaultAsyncHttpClient(), - closeClient = true) + AsyncHttpClientFutureHandler(new DefaultAsyncHttpClient(), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -52,8 +57,8 @@ object AsyncHttpClientFutureHandler { def usingConfig(cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Nothing] = - new AsyncHttpClientFutureHandler(new DefaultAsyncHttpClient(cfg), - closeClient = true) + AsyncHttpClientFutureHandler(new DefaultAsyncHttpClient(cfg), + closeClient = true) /** * @param ec The execution context for running non-network related operations, @@ -63,5 +68,5 @@ object AsyncHttpClientFutureHandler { def usingClient(client: AsyncHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Nothing] = - new AsyncHttpClientFutureHandler(client, closeClient = false) + AsyncHttpClientFutureHandler(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-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHandler.scala index 786f176..311d3ea 100644 --- a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHandler.scala +++ b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHandler.scala @@ -3,6 +3,7 @@ package com.softwaremill.sttp.asynchttpclient.monix import java.nio.ByteBuffer import com.softwaremill.sttp.{ + FollowRedirectsHandler, MonadAsyncError, SttpHandler, Utf8, @@ -50,14 +51,20 @@ class AsyncHttpClientMonixHandler private ( object AsyncHttpClientMonixHandler { + private def apply(asyncHttpClient: AsyncHttpClient, closeClient: Boolean)( + implicit scheduler: Scheduler) + : SttpHandler[Task, Observable[ByteBuffer]] = + new FollowRedirectsHandler( + new AsyncHttpClientMonixHandler(asyncHttpClient, closeClient)) + /** * @param s The scheduler used for streaming request bodies. Defaults to the * global scheduler. */ def apply()(implicit s: Scheduler = Scheduler.Implicits.global) : SttpHandler[Task, Observable[ByteBuffer]] = - new AsyncHttpClientMonixHandler(new DefaultAsyncHttpClient(), - closeClient = true) + AsyncHttpClientMonixHandler(new DefaultAsyncHttpClient(), + closeClient = true) /** * @param s The scheduler used for streaming request bodies. Defaults to the @@ -66,8 +73,8 @@ object AsyncHttpClientMonixHandler { def usingConfig(cfg: AsyncHttpClientConfig)(implicit s: Scheduler = Scheduler.Implicits.global) : SttpHandler[Task, Observable[ByteBuffer]] = - new AsyncHttpClientMonixHandler(new DefaultAsyncHttpClient(cfg), - closeClient = true) + AsyncHttpClientMonixHandler(new DefaultAsyncHttpClient(cfg), + closeClient = true) /** * @param s The scheduler used for streaming request bodies. Defaults to the @@ -76,7 +83,7 @@ object AsyncHttpClientMonixHandler { def usingClient(client: AsyncHttpClient)(implicit s: Scheduler = Scheduler.Implicits.global) : SttpHandler[Task, Observable[ByteBuffer]] = - new AsyncHttpClientMonixHandler(client, closeClient = false) + AsyncHttpClientMonixHandler(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-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHandler.scala index aea6c0e..b470606 100644 --- a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHandler.scala +++ b/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHandler.scala @@ -2,7 +2,11 @@ package com.softwaremill.sttp.asynchttpclient.scalaz import java.nio.ByteBuffer -import com.softwaremill.sttp.{MonadAsyncError, SttpHandler} +import com.softwaremill.sttp.{ + FollowRedirectsHandler, + MonadAsyncError, + SttpHandler +} import com.softwaremill.sttp.asynchttpclient.AsyncHttpClientHandler import org.asynchttpclient.{ AsyncHttpClient, @@ -33,14 +37,19 @@ class AsyncHttpClientScalazHandler private (asyncHttpClient: AsyncHttpClient, } object AsyncHttpClientScalazHandler { + private def apply(asyncHttpClient: AsyncHttpClient, + closeClient: Boolean): SttpHandler[Task, Nothing] = + new FollowRedirectsHandler[Task, Nothing]( + new AsyncHttpClientScalazHandler(asyncHttpClient, closeClient)) + def apply(): SttpHandler[Task, Nothing] = - new AsyncHttpClientScalazHandler(new DefaultAsyncHttpClient(), - closeClient = true) + AsyncHttpClientScalazHandler(new DefaultAsyncHttpClient(), + closeClient = true) def usingConfig(cfg: AsyncHttpClientConfig): SttpHandler[Task, Nothing] = - new AsyncHttpClientScalazHandler(new DefaultAsyncHttpClient(cfg), - closeClient = true) + AsyncHttpClientScalazHandler(new DefaultAsyncHttpClient(cfg), + closeClient = true) def usingClient(client: AsyncHttpClient): SttpHandler[Task, Nothing] = - new AsyncHttpClientScalazHandler(client, closeClient = false) + AsyncHttpClientScalazHandler(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-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala index 06124b7..b6c9249 100644 --- a/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala +++ b/async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala @@ -36,7 +36,7 @@ abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, closeClient: Boolean) extends SttpHandler[R, S] { - override protected def doSend[T](r: Request[T, S]): R[Response[T]] = { + override def send[T](r: Request[T, S]): R[Response[T]] = { val preparedRequest = asyncHttpClient .prepareRequest(requestToAsync(r)) |