diff options
author | adamw <adam@warski.org> | 2017-08-31 12:26:46 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-31 12:26:46 +0200 |
commit | 5bc89ddefab16dd814d0b716a72490451b697b32 (patch) | |
tree | 30d907effc67ce976af5cd01dd4c6ef4d1bc6242 /tests/src/test/scala | |
parent | 1fab77128b7ebd8a7f14d8e02c801b1fb6e28046 (diff) | |
download | sttp-5bc89ddefab16dd814d0b716a72490451b697b32.tar.gz sttp-5bc89ddefab16dd814d0b716a72490451b697b32.tar.bz2 sttp-5bc89ddefab16dd814d0b716a72490451b697b32.zip |
Follow-redirect support
Diffstat (limited to 'tests/src/test/scala')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 2275c5e..61b9c19 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -8,7 +8,7 @@ import java.time.{ZoneId, ZonedDateTime} import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding} import akka.http.scaladsl.model.headers.CacheDirectives._ import akka.http.scaladsl.model.headers._ -import akka.http.scaladsl.model.{DateTime, FormData} +import akka.http.scaladsl.model.{DateTime, FormData, StatusCodes} import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.http.scaladsl.server.directives.Credentials @@ -67,19 +67,17 @@ class BasicTests } } ~ get { parameterMap { params => - complete( - List("GET", "/echo", paramsToString(params)) - .filter(_.nonEmpty) - .mkString(" ")) + complete(List("GET", "/echo", paramsToString(params)) + .filter(_.nonEmpty) + .mkString(" ")) } } ~ post { parameterMap { params => entity(as[String]) { body: String => - complete( - List("POST", "/echo", paramsToString(params), body) - .filter(_.nonEmpty) - .mkString(" ")) + complete(List("POST", "/echo", paramsToString(params), body) + .filter(_.nonEmpty) + .mkString(" ")) } } } @@ -149,6 +147,16 @@ class BasicTests .map(v => v.mkString(", ")) } } + } ~ pathPrefix("redirect") { + path("r1") { + redirect("/redirect/r2", StatusCodes.TemporaryRedirect) + } ~ + path("r2") { + redirect("/redirect/r3", StatusCodes.PermanentRedirect) + } ~ + path("r3") { + complete("ok") + } } override def port = 51823 @@ -196,6 +204,7 @@ class BasicTests compressionTests() downloadFileTests() multipartTests() + redirectTests() def parseResponseTests(): Unit = { name should "parse response as string" in { @@ -554,6 +563,35 @@ class BasicTests } finally f.delete() } } + + def redirectTests(): Unit = { + val r1 = sttp.post(uri"$endpoint/redirect/r1") + val r2 = sttp.post(uri"$endpoint/redirect/r2") + + name should "not redirect when redirects shouldn't be followed (temporary)" in { + val resp = r1.followRedirects(false).send().force() + resp.code should be(307) + resp.body should not be ("ok") + } + + name should "not redirect when redirects shouldn't be followed (permanent)" in { + val resp = r2.followRedirects(false).send().force() + resp.code should be(308) + resp.body should not be ("ok") + } + + name should "redirect when redirects should be followed" in { + val resp = r2.send().force() + resp.code should be(200) + resp.body should be("ok") + } + + name should "redirect twice when redirects should be followed" in { + val resp = r1.send().force() + resp.code should be(200) + resp.body should be("ok") + } + } } override protected def afterAll(): Unit = { |