diff options
author | adamw <adam@warski.org> | 2017-08-03 11:38:23 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-03 11:38:23 +0200 |
commit | c07f98349ac5dc646855d00425a9dc2c3324465e (patch) | |
tree | 6f07784a68290b406a3b50a59fac36b83c5df355 /async-http-client-handler/src | |
parent | 90615deb20ce43f09371b10a25628be8d68485d8 (diff) | |
download | sttp-c07f98349ac5dc646855d00425a9dc2c3324465e.tar.gz sttp-c07f98349ac5dc646855d00425a9dc2c3324465e.tar.bz2 sttp-c07f98349ac5dc646855d00425a9dc2c3324465e.zip |
Making the response monad a top-level concept, to make it possible to write SttpHandler wrappers.
Diffstat (limited to 'async-http-client-handler/src')
-rw-r--r-- | async-http-client-handler/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientHandler.scala | 20 |
1 files changed, 6 insertions, 14 deletions
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 4824b39..f5b4569 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 @@ -5,10 +5,12 @@ import java.nio.charset.Charset import com.softwaremill.sttp.model._ import com.softwaremill.sttp.{ + ContentLengthHeader, + MonadAsyncError, + MonadError, Request, Response, - SttpHandler, - ContentLengthHeader + SttpHandler } import org.asynchttpclient.AsyncHandler.State import org.asynchttpclient.handler.StreamedAsyncHandler @@ -50,11 +52,11 @@ abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, preparedRequest .execute(eagerAsyncHandler(ra, success, error)) } - }) - } + override def responseMonad: MonadError[R] = rm + protected def streamBodyToPublisher(s: S): Publisher[ByteBuffer] protected def publisherToStreamBody(p: Publisher[ByteBuffer]): S @@ -234,16 +236,6 @@ abstract class AsyncHttpClientHandler[R[_], S](asyncHttpClient: AsyncHttpClient, } } -trait MonadAsyncError[R[_]] { - def unit[T](t: T): R[T] - def map[T, T2](fa: R[T], f: T => T2): R[T2] - def flatMap[T, T2](fa: R[T], f: T => R[T2]): R[T2] - def async[T](register: (Either[Throwable, T] => Unit) => Unit): R[T] - def error[T](t: Throwable): R[T] - - def flatten[T](ffa: R[R[T]]): R[T] = flatMap[R[T], T](ffa, identity) -} - object EmptyPublisher extends Publisher[ByteBuffer] { override def subscribe(s: Subscriber[_ >: ByteBuffer]): Unit = { s.onComplete() |