Skip to content

Commit

Permalink
Merge pull request #1348 from jkobejs/don-not-return-whole-array
Browse files Browse the repository at this point in the history
use only relative bulk get method
  • Loading branch information
Pask423 authored Mar 4, 2022
2 parents 1fd17d9 + 248a996 commit 5aab54e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions core/src/main/scala/sttp/client3/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5aab54e

Please sign in to comment.