aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala2
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/Response.scala6
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala8
3 files changed, 13 insertions, 3 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
index ddc1293..24c93f4 100644
--- a/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/HttpURLConnectionHandler.scala
@@ -199,7 +199,7 @@ object HttpURLConnectionHandler extends SttpHandler[Id, Nothing] {
Left(readResponseBody(wrappedIs, asString))
}
- Response(body, code, headers)
+ Response(body, code, 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 5a3cfe3..7551ee0 100644
--- a/core/src/main/scala/com/softwaremill/sttp/Response.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/Response.scala
@@ -21,10 +21,14 @@ import scala.util.Try
* `Left(String)`, if the request wasn't successful (status code
* 3xx, 4xx or 5xx). In this case, the response body is read into
* a `String`.
+ * @param history If redirects are followed, and there were redirects,
+ * contains responses for the intermediate requests.
+ * The first response (oldest) comes first.
*/
case class Response[T](body: Either[String, T],
code: Int,
- headers: Seq[(String, String)]) {
+ headers: Seq[(String, String)],
+ history: List[Response[Unit]]) {
def is200: Boolean = code == 200
def isSuccess: Boolean = codeIsSuccess(code)
def isRedirect: Boolean = code >= 300 && code < 400
diff --git a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala b/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala
index 26464ba..2f44840 100644
--- a/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/SttpHandler.scala
@@ -38,7 +38,13 @@ trait SttpHandler[R[_], -S] {
uri"$loc"
}
- send(request.copy[Id, T, S](uri = uri))
+ val redirectResponse = send(request.copy[Id, T, S](uri = uri))
+
+ responseMonad.map(redirectResponse) { rr =>
+ val responseNoBody =
+ response.copy(body = response.body.right.map(_ => ()))
+ rr.copy(history = responseNoBody :: rr.history)
+ }
}
}