aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorintracer <intracer@gmail.com>2018-01-09 23:12:34 +0200
committerintracer <intracer@gmail.com>2018-01-09 23:12:34 +0200
commitda85f559573c9353185cb553290082c0bbdaf6d0 (patch)
tree7f53dae8999c1d66ba668b657f3f3ac4dc57201a /core
parent200dc81942cf72974f8eb870e3b1a37ef375e4a1 (diff)
downloadsttp-da85f559573c9353185cb553290082c0bbdaf6d0.tar.gz
sttp-da85f559573c9353185cb553290082c0bbdaf6d0.tar.bz2
sttp-da85f559573c9353185cb553290082c0bbdaf6d0.zip
add status message to Response #59
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala3
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala2
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/Response.scala1
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala5
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/RequestTests.scala1
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala4
6 files changed, 10 insertions, 6 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala b/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala
index accd6b5..3b88850 100644
--- a/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/FollowRedirectsBackend.scala
@@ -32,7 +32,8 @@ class FollowRedirectsBackend[R[_], S](delegate: SttpBackend[R, S])
response.header(LocationHeader).fold(responseMonad.unit(response)) { loc =>
if (redirects >= FollowRedirectsBackend.MaxRedirects) {
- responseMonad.unit(Response(Left("Too many redirects"), 0, Nil, Nil))
+ responseMonad.unit(
+ Response(Left("Too many redirects"), 0, "", Nil, Nil))
} else {
followRedirect(request, response, redirects, loc)
}
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala
index 65b1a0c..113ce48 100644
--- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionBackend.scala
@@ -226,7 +226,7 @@ class HttpURLConnectionBackend private (
Left(readResponseBody(wrappedIs, asString, charsetFromHeaders))
}
- Response(body, code, headers, Nil)
+ Response(body, code, c.getResponseMessage, headers, Nil)
}
private def readResponseBody[T](is: InputStream,
diff --git a/core/src/main/scala/com/softwaremill/sttp/Response.scala b/core/src/main/scala/com/softwaremill/sttp/Response.scala
index 4d9c385..d01645a 100644
--- a/core/src/main/scala/com/softwaremill/sttp/Response.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/Response.scala
@@ -21,6 +21,7 @@ import scala.util.Try
*/
case class Response[T](body: Either[String, T],
code: Int,
+ message: String,
headers: Seq[(String, String)],
history: List[Response[Unit]]) {
def is200: Boolean = code == 200
diff --git a/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala b/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
index 1d5b3c6..9b4e93e 100644
--- a/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
@@ -73,6 +73,7 @@ class SttpBackendStub[R[_], S] private (
wrapResponse(
Response[Nothing](Left("Not Found: " + request.uri),
404,
+ "Not Found",
Nil,
Nil))
case Some(fb) => fb.send(request)
@@ -98,10 +99,10 @@ class SttpBackendStub[R[_], S] private (
def thenRespondWithCode(code: Int,
msg: String = ""): SttpBackendStub[R, S] = {
val body = if (code >= 200 && code < 300) Right(msg) else Left(msg)
- thenRespond(Response(body, code, Nil, Nil))
+ thenRespond(Response(body, code, msg, Nil, Nil))
}
def thenRespond[T](body: T): SttpBackendStub[R, S] =
- thenRespond(Response[T](Right(body), 200, Nil, Nil))
+ thenRespond(Response[T](Right(body), 200, "OK", Nil, Nil))
def thenRespond[T](resp: => Response[T]): SttpBackendStub[R, S] = {
val m: PartialFunction[Request[_, _], Response[_]] = {
case r if p(r) => resp
diff --git a/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala b/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala
index e62112a..5fc9d50 100644
--- a/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala
@@ -33,6 +33,7 @@ class RequestTests extends FlatSpec with Matchers {
val response =
Response(Right(()),
0,
+ "",
List((SetCookieHeader, "k1=v1"), (SetCookieHeader, "k2=v2")),
Nil)
sttp
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
index c9b94c0..f3d2cd4 100644
--- a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
@@ -20,11 +20,11 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures {
case r
if r.method == Method.POST && r.uri.path.endsWith(
List("partial10")) =>
- Response(Right(10), 200, Nil, Nil)
+ Response(Right(10), 200, "OK", Nil, Nil)
case r
if r.method == Method.POST && r.uri.path.endsWith(
List("partialAda")) =>
- Response(Right("Ada"), 200, Nil, Nil)
+ Response(Right("Ada"), 200, "OK", Nil, Nil)
})
"backend stub" should "use the first rule if it matches" in {