diff options
author | adamw <adam@warski.org> | 2017-07-21 14:43:20 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-21 14:43:20 +0200 |
commit | a6b4a71d59da928ddb326671b1058501bb1a45c5 (patch) | |
tree | 8b1a2bc5d4196ff252d5ccd00cd546657f92fd14 /tests | |
parent | 2d099f6832f6e362b9a4cd48e81a16c8d77adeaf (diff) | |
download | sttp-a6b4a71d59da928ddb326671b1058501bb1a45c5.tar.gz sttp-a6b4a71d59da928ddb326671b1058501bb1a45c5.tar.bz2 sttp-a6b4a71d59da928ddb326671b1058501bb1a45c5.zip |
AcceptEncoding + response decompression
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 0f66cc8..96fbbae 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream import java.nio.ByteBuffer import java.time.{ZoneId, ZonedDateTime} +import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding} import akka.http.scaladsl.model.{DateTime, FormData} import akka.http.scaladsl.model.headers._ import akka.http.scaladsl.model.headers.CacheDirectives._ @@ -104,6 +105,10 @@ class BasicTests }) { userName => complete(s"Hello, $userName!") } + } ~ path("compress") { + encodeResponseWith(Gzip, Deflate, NoCoding) { + complete("I'm compressed!") + } } override def port = 51823 @@ -133,6 +138,7 @@ class BasicTests errorsTests() cookiesTests() authTests() + compressionTests() def parseResponseTests(): Unit = { name should "parse response as string" in { @@ -338,5 +344,37 @@ class BasicTests resp.body should be("Hello, adam!") } } + + def compressionTests(): Unit = { + val compress = sttp.get(uri"$endpoint/compress") + val decompressedBody = "I'm compressed!" + + name should "decompress using the default accept encoding header" in { + val req = compress + val resp = req.send().force() + resp.body should be(decompressedBody) + } + + name should "decompress using gzip" in { + val req = + compress.header("Accept-Encoding", "gzip", replaceExisting = true) + val resp = req.send().force() + resp.body should be(decompressedBody) + } + + name should "decompress using deflate" in { + val req = + compress.header("Accept-Encoding", "deflate", replaceExisting = true) + val resp = req.send().force() + resp.body should be(decompressedBody) + } + + name should "work despite providing an unsupported encoding" in { + val req = + compress.header("Accept-Encoding", "br", replaceExisting = true) + val resp = req.send().force() + resp.body should be(decompressedBody) + } + } } } |