@@ -12,6 +12,10 @@ import HttpTest.endpoint
1212import org .scalatest .freespec .AsyncFreeSpecLike
1313import sttp .client4 .wrappers .{DigestAuthenticationBackend , FollowRedirectsBackend , TooManyRedirectsException }
1414import sttp .model .headers .CookieWithMeta
15+ import sttp .model .Encodings
16+ import java .util .zip .GZIPInputStream
17+ import java .io .ByteArrayInputStream
18+ import java .util .zip .InflaterInputStream
1519
1620trait HttpTestExtensions [F [_]] extends AsyncFreeSpecLike { self : HttpTest [F ] =>
1721 protected def supportsResponseAsInputStream = true
@@ -198,6 +202,40 @@ trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] =>
198202 }
199203 }
200204
205+ " compression" - {
206+ " should compress request body using gzip" in {
207+ val req = basicRequest
208+ .compressBody(Encodings .Gzip )
209+ .response(asByteArrayAlways)
210+ .post(uri " $endpoint/echo/exact " )
211+ .body(" I'm not compressed" )
212+ req.send(backend).toFuture().map { resp =>
213+ resp.code shouldBe StatusCode .Ok
214+
215+ val gzipInputStream = new GZIPInputStream (new ByteArrayInputStream (resp.body))
216+ val decompressedBytes = gzipInputStream.readAllBytes()
217+
218+ new String (decompressedBytes) shouldBe " I'm not compressed"
219+ }
220+ }
221+
222+ " should compress request body using deflate" in {
223+ val req = basicRequest
224+ .compressBody(Encodings .Deflate )
225+ .response(asByteArrayAlways)
226+ .post(uri " $endpoint/echo/exact " )
227+ .body(" I'm not compressed" )
228+ req.send(backend).toFuture().map { resp =>
229+ resp.code shouldBe StatusCode .Ok
230+
231+ val inflaterInputStream = new InflaterInputStream (new ByteArrayInputStream (resp.body))
232+ val decompressedBytes = inflaterInputStream.readAllBytes()
233+
234+ new String (decompressedBytes) shouldBe " I'm not compressed"
235+ }
236+ }
237+ }
238+
201239 private def withTemporaryFile [T ](content : Option [Array [Byte ]])(f : File => Future [T ]): Future [T ] = {
202240 val file = Files .createTempFile(" sttp" , " sttp" )
203241 val result = Future {
0 commit comments