Skip to content

Commit

Permalink
Only test on jvm
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Dec 28, 2024
1 parent 1e65bda commit 1745ded
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
35 changes: 0 additions & 35 deletions core/src/test/scala/sttp/client4/testing/HttpTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1745ded

Please sign in to comment.