diff --git a/zio-http/src/main/scala/zhttp/http/HttpData.scala b/zio-http/src/main/scala/zhttp/http/HttpData.scala index 6959942d3e..e04f554419 100644 --- a/zio-http/src/main/scala/zhttp/http/HttpData.scala +++ b/zio-http/src/main/scala/zhttp/http/HttpData.scala @@ -95,7 +95,7 @@ object HttpData { case HttpData.BinaryStream(stream) => stream .asInstanceOf[ZStream[Any, Throwable, ByteBuf]] - .fold(Unpooled.compositeBuffer())((c, b) => c.addComponent(b)) + .fold(Unpooled.compositeBuffer())((c, b) => c.addComponent(true, b)) case HttpData.RandomAccessFile(raf) => effectBlocking { val fis = new FileInputStream(raf().getFD) diff --git a/zio-http/src/test/scala/zhttp/http/HttpDataSpec.scala b/zio-http/src/test/scala/zhttp/http/HttpDataSpec.scala index 44da146fe6..a25545429c 100644 --- a/zio-http/src/test/scala/zhttp/http/HttpDataSpec.scala +++ b/zio-http/src/test/scala/zhttp/http/HttpDataSpec.scala @@ -1,16 +1,29 @@ package zhttp.http +import zio.stream.ZStream import zio.test.Assertion.equalTo -import zio.test.{DefaultRunnableSpec, assertM} +import zio.test.{DefaultRunnableSpec, Gen, assertM, checkAllM} import java.io.File object HttpDataSpec extends DefaultRunnableSpec { // TODO : Add tests for othe HttpData types override def spec = - suite("HttpDataSpec")(suite("Test toByteBuf")(testM("HttpData.fromFile") { - val file = new File(getClass.getResource("/TestFile.txt").getPath) - val res = HttpData.fromFile(file).toByteBuf.map(_.toString(HTTP_CHARSET)) - assertM(res)(equalTo("abc\nfoo")) - })) + suite("HttpDataSpec")( + suite("Test toByteBuf")( + testM("HttpData.fromFile") { + val file = new File(getClass.getResource("/TestFile.txt").getPath) + val res = HttpData.fromFile(file).toByteBuf.map(_.toString(HTTP_CHARSET)) + assertM(res)(equalTo("abc\nfoo")) + }, + testM("HttpData.fromStream") { + checkAllM(Gen.anyString) { payload => + val stringBuffer = payload.toString.getBytes(HTTP_CHARSET) + val responseContent = ZStream.fromIterable(stringBuffer) + val res = HttpData.fromStream(responseContent).toByteBuf.map(_.toString(HTTP_CHARSET)) + assertM(res)(equalTo(payload)) + } + }, + ), + ) }