diff options
author | adamw <adam@warski.org> | 2017-12-06 20:43:31 +0100 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-12-06 20:43:31 +0100 |
commit | 3fb284c3c8849baa0f7b0d34ee9be78af7935bb6 (patch) | |
tree | 7231538c4dea18f7fec658bb421b2315a43180a3 /tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | |
parent | a70053c72809c2588716c371a4d4f2a7404106d6 (diff) | |
download | sttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.tar.gz sttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.tar.bz2 sttp-3fb284c3c8849baa0f7b0d34ee9be78af7935bb6.zip |
#53: using proper encoding when reading the response body
Diffstat (limited to 'tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 18ff6ae..af5c5ae 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, StatusCodes} +import akka.http.scaladsl.model._ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.http.scaladsl.server.directives.Credentials @@ -55,6 +55,7 @@ class BasicTests private val binaryFile = new java.io.File("tests/src/test/resources/binaryfile.jpg") private val outPath = Paths.get("out") + private val textWithSpecialCharacters = "Żółć!" override val serverRoutes: Route = pathPrefix("echo") { @@ -181,6 +182,13 @@ class BasicTests protocol = HttpProtocols.`HTTP/1.1` )) } + } ~ path("respond_with_iso_8859_2") { + get { ctx => + val entity = HttpEntity( + MediaTypes.`text/plain`.withCharset(HttpCharset.custom("ISO-8859-2")), + textWithSpecialCharacters) + ctx.complete(HttpResponse(200, entity = entity)) + } } override def port = 51823 @@ -232,6 +240,7 @@ class BasicTests redirectTests() timeoutTests() emptyResponseTests() + encodingTests() def parseResponseTests(): Unit = { name should "parse response as string" in { @@ -688,6 +697,14 @@ class BasicTests response.body should be(Left("")) } } + + def encodingTests(): Unit = { + name should "read response body encoded using ISO-8859-2, as specified in the header, overriding the default" in { + val request = sttp.get(uri"$endpoint/respond_with_iso_8859_2") + + request.send().force().unsafeBody should be(textWithSpecialCharacters) + } + } } override protected def afterAll(): Unit = { |