diff options
author | adamw <adam@warski.org> | 2017-08-02 14:11:48 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-02 14:11:48 +0200 |
commit | 54715a9bbcfb7b9c6cad1f5dc46498f07b9612b6 (patch) | |
tree | 1da5e95965ee810d40a465a2855bc52df1d9a049 /core/src/main | |
parent | 4fd5b1570c006a7ad5e022cadb9f41decf51d866 (diff) | |
download | sttp-54715a9bbcfb7b9c6cad1f5dc46498f07b9612b6.tar.gz sttp-54715a9bbcfb7b9c6cad1f5dc46498f07b9612b6.tar.bz2 sttp-54715a9bbcfb7b9c6cad1f5dc46498f07b9612b6.zip |
ResponseAsParams is not needed, it's enough to parse the string into parameters
Diffstat (limited to 'core/src/main')
3 files changed, 11 insertions, 14 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionSttpHandler.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionSttpHandler.scala index fc9b420..6c3368a 100644 --- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionSttpHandler.scala +++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionSttpHandler.scala @@ -129,9 +129,6 @@ object HttpURLConnectionSttpHandler extends SttpHandler[Id, Nothing] { os.toByteArray - case r @ ResponseAsParams(enc) => - r.parse(asString(enc)) - case ResponseAsStream() => // only possible when the user requests the response as a stream of // Nothing. Oh well ... diff --git a/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala b/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala index 4724292..cf9bc12 100644 --- a/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala +++ b/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala @@ -17,10 +17,17 @@ case object IgnoreResponse extends ResponseAs[Unit, Nothing] case class ResponseAsString(encoding: String) extends ResponseAs[String, Nothing] case object ResponseAsByteArray extends ResponseAs[Array[Byte], Nothing] -case class ResponseAsParams(encoding: String) - extends ResponseAs[Seq[(String, String)], Nothing] { +case class ResponseAsStream[T, S]()(implicit val responseIsStream: S =:= T) + extends ResponseAs[T, S] +case class MappedResponseAs[T, T2, S](raw: ResponseAs[T, S], g: T => T2) + extends ResponseAs[T2, S] { + override def map[T3](f: T2 => T3): ResponseAs[T3, S] = + MappedResponseAs[T, T3, S](raw, g andThen f) +} - private[sttp] def parse(s: String): Seq[(String, String)] = { +object ResponseAs { + private[sttp] def parseParams(s: String, + encoding: String): Seq[(String, String)] = { s.split("&") .toList .flatMap(kv => @@ -32,10 +39,3 @@ case class ResponseAsParams(encoding: String) }) } } -case class ResponseAsStream[T, S]()(implicit val responseIsStream: S =:= T) - extends ResponseAs[T, S] -case class MappedResponseAs[T, T2, S](raw: ResponseAs[T, S], g: T => T2) - extends ResponseAs[T2, S] { - override def map[T3](f: T2 => T3): ResponseAs[T3, S] = - MappedResponseAs[T, T3, S](raw, g andThen f) -} diff --git a/core/src/main/scala/com/softwaremill/sttp/package.scala b/core/src/main/scala/com/softwaremill/sttp/package.scala index c786720..daba574 100644 --- a/core/src/main/scala/com/softwaremill/sttp/package.scala +++ b/core/src/main/scala/com/softwaremill/sttp/package.scala @@ -84,7 +84,7 @@ package object sttp { def asParams: ResponseAs[Seq[(String, String)], Nothing] = asParams(Utf8) def asParams(encoding: String): ResponseAs[Seq[(String, String)], Nothing] = - ResponseAsParams(encoding) + asString(encoding).map(ResponseAs.parseParams(_, encoding)) def asStream[S]: ResponseAs[S, S] = ResponseAsStream[S, S]() |