Closed tom91136 closed 3 years ago
Sorry for the late response :) As you have the code ready, if you could do a PR which fixes the problem that would be great. Do you have a test for that as well? If so, this could guide the Akka implementation
Thanks for getting back! I'll prepare a PR and add some tests.
Thanks for getting this through and sorry about the silence, lots of paper deadlines last month.
Tapir version: 0.17.1
Scala version: 2.13.4
Describe the bug
While using the Fs2 based WebSocket client implementation (backed by JDK HttpClient), I noticed long text messages are truncated. In my case I was using circe to encode/decode the messages so it wasn't obvious this was happening.
Digging deeper, I found:
https://github.com/softwaremill/tapir/blob/2b06de7e804802083651c4efcbd919bccb3bd555/client/sttp-client/src/main/scalajvm/sttp/tapir/client/sttp/ws/fs2/WebSocketToFs2Pipe.scala#L22
So client's send implementation doesn't handle fragmentation, which is fine as WebSocket doesn't impose a meaningful base frame size limit. For comparison, the Tapir's Http4s fs2 WebSocket server implementation fragments messages into 16KB frames.
We do have an actual bug in the
receives
stream where aBinary
orText
frame is decoded as-is without proper fragmentation handling:https://github.com/softwaremill/tapir/blob/2b06de7e804802083651c4efcbd919bccb3bd555/client/sttp-client/src/main/scalajvm/sttp/tapir/client/sttp/ws/fs2/WebSocketToFs2Pipe.scala#L31-L36
To verify this, I've implemented a custom
WebSocketToPipe[R]
where the receiving end handles fragmentation appropriately:And everything works as expected. Akka version looks to have identical issues.
If we only want to address the receive fragmentation bug I can open a PR for this is you guys are cool with that, although I don't have much experience on the Akka side.