diff --git a/core/src/test/scala/sttp/client4/testing/HttpTest.scala b/core/src/test/scala/sttp/client4/testing/HttpTest.scala index 3e4a67c82..ad368c06d 100644 --- a/core/src/test/scala/sttp/client4/testing/HttpTest.scala +++ b/core/src/test/scala/sttp/client4/testing/HttpTest.scala @@ -14,9 +14,6 @@ import java.io.{ByteArrayInputStream, UnsupportedEncodingException} import java.nio.ByteBuffer import scala.concurrent.Future import scala.concurrent.duration._ -import sttp.model.Encodings -import java.util.zip.GZIPInputStream -import java.util.zip.InflaterInputStream trait HttpTest[F[_]] extends AsyncFreeSpec @@ -467,38 +464,6 @@ trait HttpTest[F[_]] } } } - - "should compress request body using gzip" in { - val req = basicRequest - .compressBody(Encodings.Gzip) - .response(asByteArrayAlways) - .post(uri"$endpoint/echo/exact") - .body("I'm not compressed") - req.send(backend).toFuture().map { resp => - resp.code shouldBe StatusCode.Ok - - val gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(resp.body)) - val decompressedBytes = gzipInputStream.readAllBytes() - - new String(decompressedBytes) shouldBe "I'm not compressed" - } - } - - "should compress request body using deflate" in { - val req = basicRequest - .compressBody(Encodings.Deflate) - .response(asByteArrayAlways) - .post(uri"$endpoint/echo/exact") - .body("I'm not compressed") - req.send(backend).toFuture().map { resp => - resp.code shouldBe StatusCode.Ok - - val inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(resp.body)) - val decompressedBytes = inflaterInputStream.readAllBytes() - - new String(decompressedBytes) shouldBe "I'm not compressed" - } - } } // in JavaScript the only way to set the content type is to use a Blob which defaults the filename to 'blob' diff --git a/core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala b/core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala index 9f82a32ac..52938cacd 100644 --- a/core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala +++ b/core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala @@ -12,6 +12,10 @@ import HttpTest.endpoint import org.scalatest.freespec.AsyncFreeSpecLike import sttp.client4.wrappers.{DigestAuthenticationBackend, FollowRedirectsBackend, TooManyRedirectsException} import sttp.model.headers.CookieWithMeta +import sttp.model.Encodings +import java.util.zip.GZIPInputStream +import java.io.ByteArrayInputStream +import java.util.zip.InflaterInputStream trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] => protected def supportsResponseAsInputStream = true @@ -198,6 +202,40 @@ trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] => } } + "compression" - { + "should compress request body using gzip" in { + val req = basicRequest + .compressBody(Encodings.Gzip) + .response(asByteArrayAlways) + .post(uri"$endpoint/echo/exact") + .body("I'm not compressed") + req.send(backend).toFuture().map { resp => + resp.code shouldBe StatusCode.Ok + + val gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(resp.body)) + val decompressedBytes = gzipInputStream.readAllBytes() + + new String(decompressedBytes) shouldBe "I'm not compressed" + } + } + + "should compress request body using deflate" in { + val req = basicRequest + .compressBody(Encodings.Deflate) + .response(asByteArrayAlways) + .post(uri"$endpoint/echo/exact") + .body("I'm not compressed") + req.send(backend).toFuture().map { resp => + resp.code shouldBe StatusCode.Ok + + val inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(resp.body)) + val decompressedBytes = inflaterInputStream.readAllBytes() + + new String(decompressedBytes) shouldBe "I'm not compressed" + } + } + } + private def withTemporaryFile[T](content: Option[Array[Byte]])(f: File => Future[T]): Future[T] = { val file = Files.createTempFile("sttp", "sttp") val result = Future {