diff options
author | adamw <adam@warski.org> | 2017-07-04 14:01:16 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-04 14:01:16 +0200 |
commit | 3aefd7447ae8f15ecd9a3401b9dd6992c4197aec (patch) | |
tree | f0a8eca053eb3573174c244e06ded4a310a0d1db /core/src/main/scala/com | |
parent | 09da476faedc382d7f2604be142a353e5851a1e3 (diff) | |
download | sttp-3aefd7447ae8f15ecd9a3401b9dd6992c4197aec.tar.gz sttp-3aefd7447ae8f15ecd9a3401b9dd6992c4197aec.tar.bz2 sttp-3aefd7447ae8f15ecd9a3401b9dd6992c4197aec.zip |
Stream type is nothing when the response doesn't support streaming
Diffstat (limited to 'core/src/main/scala/com')
4 files changed, 15 insertions, 42 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpConnectionSttpHandler.scala b/core/src/main/scala/com/softwaremill/sttp/HttpConnectionSttpHandler.scala index f7292d7..1ca2f77 100644 --- a/core/src/main/scala/com/softwaremill/sttp/HttpConnectionSttpHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/HttpConnectionSttpHandler.scala @@ -10,8 +10,8 @@ import com.softwaremill.sttp.model._ import scala.annotation.tailrec import scala.io.Source -object HttpConnectionSttpHandler extends SttpHandler[Id, Any, ResponseAsBasic] { - override def send[T](r: Request, responseAs: ResponseAsBasic[T, Any]): Response[T] = { +object HttpConnectionSttpHandler extends SttpHandler[Id, Nothing, ResponseAsBasic] { + override def send[T](r: Request, responseAs: ResponseAsBasic[T, Nothing]): Response[T] = { val c = r.uri.toURL.openConnection().asInstanceOf[HttpURLConnection] c.setRequestMethod(r.method.m) r.headers.foreach { case (k, v) => c.setRequestProperty(k, v) } @@ -68,7 +68,7 @@ object HttpConnectionSttpHandler extends SttpHandler[Id, Any, ResponseAsBasic] { } } - private def readResponse[T](is: InputStream, responseAs: ResponseAsBasic[T, Any]): T = responseAs match { + private def readResponse[T](is: InputStream, responseAs: ResponseAsBasic[T, Nothing]): T = responseAs match { case IgnoreResponse => @tailrec def consume(): Unit = if (is.read() != -1) consume() consume() diff --git a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala b/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala index 50ccd35..500e889 100644 --- a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala @@ -1,36 +1,9 @@ package com.softwaremill.sttp -import com.softwaremill.sttp.model.{ResponseAs, ResponseAsStream} +import com.softwaremill.sttp.model.ResponseAs import scala.language.higherKinds -trait SttpHandler[R[_], +S, -AcceptsResponseAs[x, -s] <: ResponseAs[x, s]] { +trait SttpHandler[R[_], -S, -AcceptsResponseAs[x, +s] <: ResponseAs[x, s]] { def send[T](request: Request, responseAs: AcceptsResponseAs[T, S]): R[Response[T]] } - -//trait SttpStreamHandler[R[_], S] extends SttpHandler[R] { -// def send(request: Request, responseAsStream: ResponseAsStream[S]): R[Response[S]] -//} - - -/* - -Cat <: Animal -Dog <: Animal - -x: Animal := Cat - -Contravariant: -def eat(x: Cat) := def eat(x: Animal) -Animal => Cat := Animal => Unit - -Covariant: -def create: Animal := def create: Cat -Unit => Animal := Unit => Cat - ---- - -RA >: RAS -Handler[RAS] >: Handler[RA] - - */
\ No newline at end of file diff --git a/core/src/main/scala/com/softwaremill/sttp/model/package.scala b/core/src/main/scala/com/softwaremill/sttp/model/package.scala index 3c0e563..24c5fa6 100644 --- a/core/src/main/scala/com/softwaremill/sttp/model/package.scala +++ b/core/src/main/scala/com/softwaremill/sttp/model/package.scala @@ -38,12 +38,12 @@ package object model { case class FileBody(f: File) extends BasicRequestBody case class PathBody(f: Path) extends BasicRequestBody - sealed trait ResponseAs[T, -S] + sealed trait ResponseAs[T, +S] - sealed trait ResponseAsBasic[T, -S <: Any] extends ResponseAs[T, S] - object IgnoreResponse extends ResponseAsBasic[Unit, Any] - case class ResponseAsString(encoding: String) extends ResponseAsBasic[String, Any] - object ResponseAsByteArray extends ResponseAsBasic[Array[Byte], Any] + sealed trait ResponseAsBasic[T, +S] extends ResponseAs[T, S] + object IgnoreResponse extends ResponseAsBasic[Unit, Nothing] + case class ResponseAsString(encoding: String) extends ResponseAsBasic[String, Nothing] + object ResponseAsByteArray extends ResponseAsBasic[Array[Byte], Nothing] // response as params case class ResponseAsStream[T, S]()(implicit val x: S =:= T) extends ResponseAs[T, S] diff --git a/core/src/main/scala/com/softwaremill/sttp/package.scala b/core/src/main/scala/com/softwaremill/sttp/package.scala index e4f5311..8abea0a 100644 --- a/core/src/main/scala/com/softwaremill/sttp/package.scala +++ b/core/src/main/scala/com/softwaremill/sttp/package.scala @@ -15,13 +15,13 @@ package object sttp { type Id[X] = X type Empty[X] = None.type - def ignoreResponse: ResponseAsBasic[Unit, Any] = IgnoreResponse + def ignoreResponse: ResponseAsBasic[Unit, Nothing] = IgnoreResponse /** * Uses `utf-8` encoding. */ - def responseAsString: ResponseAsBasic[String, Any] = responseAsString(Utf8) - def responseAsString(encoding: String): ResponseAsBasic[String, Any] = ResponseAsString(encoding) - def responseAsByteArray: ResponseAsBasic[Array[Byte], Any] = ResponseAsByteArray + def responseAsString: ResponseAsBasic[String, Nothing] = responseAsString(Utf8) + def responseAsString(encoding: String): ResponseAsBasic[String, Nothing] = ResponseAsString(encoding) + def responseAsByteArray: ResponseAsBasic[Array[Byte], Nothing] = ResponseAsByteArray def responseAsStream[S]: ResponseAs[S, S] = ResponseAsStream[S, S]() /** @@ -150,7 +150,7 @@ package object sttp { * 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. */ - def send[R[_], S, T, ResponseAsType[x, -s] <: ResponseAs[x, s]](responseAs: ResponseAsType[T, S])( + def send[R[_], S, T, ResponseAsType[x, s] <: ResponseAs[x, s]](responseAs: ResponseAsType[T, S])( implicit handler: SttpHandler[R, S, ResponseAsType], isRequest: IsRequest[U]): R[Response[T]] = { handler.send(this, responseAs) } |