diff --git a/akka-http-backend/src/main/scala/sttp/client4/akkahttp/BodyFromAkka.scala b/akka-http-backend/src/main/scala/sttp/client4/akkahttp/BodyFromAkka.scala index 654ce5d35d..c81cb6d445 100644 --- a/akka-http-backend/src/main/scala/sttp/client4/akkahttp/BodyFromAkka.scala +++ b/akka-http-backend/src/main/scala/sttp/client4/akkahttp/BodyFromAkka.scala @@ -47,7 +47,7 @@ private[akkahttp] class BodyFromAkka()(implicit ec: ExecutionContext, mat: Mater override protected def regularAsByteArray(response: HttpResponse): Future[Array[Byte]] = response.entity.dataBytes .runFold(ByteString(""))(_ ++ _) - .map(_.toArray[Byte]) + .map(_.toArrayUnsafe()) override protected def regularAsFile(response: HttpResponse, file: SttpFile): Future[SttpFile] = { val f = file.toFile @@ -203,13 +203,13 @@ private[akkahttp] class BodyFromAkka()(implicit ec: ExecutionContext, mat: Mater case msg: TextMessage => msg.textStream.runFold("")(_ + _).map(t => WebSocketFrame.text(t)) case msg: BinaryMessage => - msg.dataStream.runFold(ByteString.empty)(_ ++ _).map(b => WebSocketFrame.binary(b.toArray)) + msg.dataStream.runFold(ByteString.empty)(_ ++ _).map(b => WebSocketFrame.binary(b.toArrayUnsafe())) } private def frameToMessage(w: WebSocketFrame): Option[Message] = w match { case WebSocketFrame.Text(p, _, _) => Some(TextMessage(p)) - case WebSocketFrame.Binary(p, _, _) => Some(BinaryMessage(ByteString(p))) + case WebSocketFrame.Binary(p, _, _) => Some(BinaryMessage(ByteString.fromArrayUnsafe(p))) case WebSocketFrame.Ping(_) => None case WebSocketFrame.Pong(_) => None case WebSocketFrame.Close(_, _) => throw WebSocketClosed(None) diff --git a/pekko-http-backend/src/main/scala/sttp/client4/pekkohttp/BodyFromPekko.scala b/pekko-http-backend/src/main/scala/sttp/client4/pekkohttp/BodyFromPekko.scala index b34d40a036..cfd05f3cb7 100644 --- a/pekko-http-backend/src/main/scala/sttp/client4/pekkohttp/BodyFromPekko.scala +++ b/pekko-http-backend/src/main/scala/sttp/client4/pekkohttp/BodyFromPekko.scala @@ -48,7 +48,7 @@ private[pekkohttp] class BodyFromPekko()(implicit ec: ExecutionContext, mat: Mat override protected def regularAsByteArray(response: HttpResponse): Future[Array[Byte]] = response.entity.dataBytes .runFold(ByteString(""))(_ ++ _) - .map(_.toArray[Byte]) + .map(_.toArrayUnsafe()) override protected def regularAsFile(response: HttpResponse, file: SttpFile): Future[SttpFile] = { val f = file.toFile @@ -204,13 +204,13 @@ private[pekkohttp] class BodyFromPekko()(implicit ec: ExecutionContext, mat: Mat case msg: TextMessage => msg.textStream.runFold("")(_ + _).map(t => WebSocketFrame.text(t)) case msg: BinaryMessage => - msg.dataStream.runFold(ByteString.empty)(_ ++ _).map(b => WebSocketFrame.binary(b.toArray)) + msg.dataStream.runFold(ByteString.empty)(_ ++ _).map(b => WebSocketFrame.binary(b.toArrayUnsafe())) } private def frameToMessage(w: WebSocketFrame): Option[Message] = w match { case WebSocketFrame.Text(p, _, _) => Some(TextMessage(p)) - case WebSocketFrame.Binary(p, _, _) => Some(BinaryMessage(ByteString(p))) + case WebSocketFrame.Binary(p, _, _) => Some(BinaryMessage(ByteString.fromArrayUnsafe(p))) case WebSocketFrame.Ping(_) => None case WebSocketFrame.Pong(_) => None case WebSocketFrame.Close(_, _) => throw WebSocketClosed(None)