diff options
author | adamw <adam@warski.org> | 2017-07-24 16:57:51 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-24 16:57:51 +0200 |
commit | b1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6 (patch) | |
tree | 6ef95abd69930cabb5b7566507af6dc56d25ebaf /async-http-client-handler/future/src | |
parent | 95fee5083274bf0e856af8b868702f8965b92f1a (diff) | |
download | sttp-b1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6.tar.gz sttp-b1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6.tar.bz2 sttp-b1a539bd1fb5a5870c2e96c73f14e79b6caf4ff6.zip |
Adding streaming to the monix async http client handler
Diffstat (limited to 'async-http-client-handler/future/src')
-rw-r--r-- | async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala index adc679e..a2e49a2 100644 --- a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala +++ b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala @@ -1,5 +1,7 @@ package com.softwaremill.sttp.asynchttpclient.future +import java.nio.ByteBuffer + import com.softwaremill.sttp.asynchttpclient.{ AsyncHttpClientHandler, MonadAsyncError @@ -9,22 +11,50 @@ import org.asynchttpclient.{ AsyncHttpClientConfig, DefaultAsyncHttpClient } +import org.reactivestreams.Publisher import scala.concurrent.{ExecutionContext, Future, Promise} class FutureAsyncHttpClientHandler private (asyncHttpClient: AsyncHttpClient)( implicit ec: ExecutionContext) - extends AsyncHttpClientHandler[Future](asyncHttpClient, new FutureMonad()) + extends AsyncHttpClientHandler[Future, Nothing](asyncHttpClient, + new FutureMonad()) { + + override protected def streamBodyToPublisher( + s: Nothing): Publisher[ByteBuffer] = s // nothing is everything + + override protected def publisherToStreamBody( + p: Publisher[ByteBuffer]): Nothing = + throw new IllegalStateException("This handler does not support streaming") +} object FutureAsyncHttpClientHandler { + + /** + * @param ec The execution context for running non-network related operations, + * e.g. mapping responses. Defaults to the global execution + * context. + */ def apply()( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient()) + + /** + * @param ec The execution context for running non-network related operations, + * e.g. mapping responses. Defaults to the global execution + * context. + */ def usingConfig(cfg: AsyncHttpClientConfig)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient()) + + /** + * @param ec The execution context for running non-network related operations, + * e.g. mapping responses. Defaults to the global execution + * context. + */ def usingClient(client: AsyncHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : FutureAsyncHttpClientHandler = |