fix: prevent double serialization of websocket text messages (#6173)#6182
Conversation
|
Thanks for the PR @Praveenkumar02023 Assigning this to @sid-bruno @anusree-bruno to get this reviewed and merged |
|
Hey @Praveenkumar02023, Thanks for the fix! This is leftover code from when WS only supported JSON messages, and there are a few more changes we’d like to make so things are a bit more robust. If you’re up for it, we’d like to pass the WS request’s selected body type down to sendMessage and use that to determine whether something needs to be sanitized as JSON and stringified, or just sent as a string. Otherwise, I can pick up the PR and make the changes. |
|
Hi Sid, Please feel free to make the changes. |
Understood, cool, i'll take this up |
|
hey sid , |
|
Hey @Praveenkumar02023, |
a4892bf
into
usebruno:fix/websocket-serialization-6173
|
Merging to extend, the rest of the mods will be done on #6479 , you can subscribe for that |
…#6479) * fix: prevent double serialization of websocket text messages. (#6182) * fix: improve websocket message handling and serialization - Added normalization for message format to prevent double encoding. - Updated queueMessage and sendMessage methods to handle message format. - Refactored code for better readability and maintainability. fix: enhance message normalization in WebSocket client --------- Co-authored-by: Praveen kumar <praveenkumar042023@gmail.com>
Description
Fixes #6173
This PR fixes a bug where WebSocket messages sent using the "TEXT" message type were being incorrectly serialized as JSON strings (e.g., sending
"message"instead ofmessage). This resulted in the server receiving payloads wrapped in unwanted double quotes.Changes:
packages/bruno-requests/src/ws/ws-client.js.sendMessagefunction to conditionally stringify the payload.messageToSendis already a string (TEXT mode), it is passed to the socket raw. If it is an object (JSON mode), it is stringified viaJSON.stringify.Verification:
Contribution Checklist: