diff --git a/core/src/main/scala/sttp/client3/internal/package.scala b/core/src/main/scala/sttp/client3/internal/package.scala index 352c5b301f..b1c601a711 100644 --- a/core/src/main/scala/sttp/client3/internal/package.scala +++ b/core/src/main/scala/sttp/client3/internal/package.scala @@ -80,13 +80,9 @@ package object internal { implicit class RichByteBuffer(byteBuffer: ByteBuffer) { def safeRead(): Array[Byte] = { - if (byteBuffer.hasArray) { - byteBuffer.array() - } else { - val array = new Array[Byte](byteBuffer.remaining()) - byteBuffer.get(array) - array - } + val array = new Array[Byte](byteBuffer.remaining()) + byteBuffer.get(array) + array } } } diff --git a/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala b/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala index 9791dd5a69..bf38b736cd 100644 --- a/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala +++ b/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala @@ -105,12 +105,12 @@ private[httpclient] class AddToQueueListener[F[_]]( } override def onPing(webSocket: JWebSocket, message: ByteBuffer): CompletionStage[_] = { - onFrame(WebSocketFrame.Ping(message.array())) + onFrame(WebSocketFrame.Ping(message.safeRead())) null } override def onPong(webSocket: JWebSocket, message: ByteBuffer): CompletionStage[_] = { - onFrame(WebSocketFrame.Pong(message.array())) + onFrame(WebSocketFrame.Pong(message.safeRead())) null }