aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Warski <adam@warski.org>2018-01-11 17:35:42 +0100
committerGitHub <noreply@github.com>2018-01-11 17:35:42 +0100
commit7999c22968d7efe449ccdcfce74c8b2ab3c32689 (patch)
tree7cfc40dfbff54fa1ea56cbe904b131bda9063d06
parent200dc81942cf72974f8eb870e3b1a37ef375e4a1 (diff)
parent2a3c7c3faab7397aee63d219589c8eac623ec26a (diff)
downloadsttp-7999c22968d7efe449ccdcfce74c8b2ab3c32689.tar.gz
sttp-7999c22968d7efe449ccdcfce74c8b2ab3c32689.tar.bz2
sttp-7999c22968d7efe449ccdcfce74c8b2ab3c32689.zip
Merge pull request #60 from intracer/add_status_message
add status message to Response #59
-rw-r--r--akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala3
-rw-r--r--async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala1
-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
-rw-r--r--okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpBackend.scala3
9 files changed, 15 insertions, 8 deletions
diff --git a/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala b/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala
index 91126e9..5956793 100644
--- a/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala
+++ b/akka-http-backend/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpBackend.scala
@@ -75,6 +75,7 @@ class AkkaHttpBackend private (
log = customLog.getOrElse(actorSystem.log)))
.flatMap { hr =>
val code = hr.status.intValue()
+ val statusText = hr.status.reason()
val headers = headersFromAkka(hr)
val charsetFromHeaders = headers
@@ -90,7 +91,7 @@ class AkkaHttpBackend private (
.map(Left(_))
}
- body.map(Response(_, code, headers, Nil))
+ body.map(Response(_, code, statusText, headers, Nil))
}
}
diff --git a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
index 885e5a9..fb0f780 100644
--- a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
+++ b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
@@ -252,6 +252,7 @@ abstract class AsyncHttpClientBackend[R[_], S](asyncHttpClient: AsyncHttpClient,
private def readResponseNoBody(response: AsyncResponse): Response[Unit] = {
Response(Right(()),
response.getStatusCode,
+ response.getStatusText,
response.getHeaders
.iterator()
.asScala
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..e38ae4a 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,
+ statusText: 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 {
diff --git a/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpBackend.scala b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpBackend.scala
index 650d179..5716245 100644
--- a/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpBackend.scala
+++ b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpBackend.scala
@@ -107,7 +107,8 @@ abstract class OkHttpBackend[R[_], S](client: OkHttpClient,
.asScala
.flatMap(name => res.headers().values(name).asScala.map((name, _)))
- responseMonad.map(body)(Response(_, res.code(), headers.toList, Nil))
+ responseMonad.map(body)(
+ Response(_, res.code(), res.message(), headers.toList, Nil))
}
private def responseHandler(res: OkHttpResponse) =