Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better support for binary data on WebSocket connections #5897

Conversation

filfreire
Copy link
Member

@filfreire filfreire commented Apr 18, 2023

Closes INS-2574
Closes #5864

changelog(Improvements): Add better support for binary data on WebSocket connections

image

@filfreire filfreire requested a review from a team April 18, 2023 10:07
@filfreire filfreire changed the title add /binary data endpoint to smoke test server Add better support for binary data on WebSocket connections Apr 19, 2023
@filfreire filfreire force-pushed the feature/ins-2574-handle-binary-data-in-websockets branch from 1cfc1db to 15e8ba8 Compare April 21, 2023 13:37
@filfreire filfreire marked this pull request as ready for review April 21, 2023 14:36
@filfreire filfreire enabled auto-merge April 21, 2023 16:52
if ('data' in event && typeof event.data === 'object') {
return 'Binary data';
}
return event.data.toString('utf-8');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utf8 is the default toString of a buffer so we shouldn't need to specify this

raw = Buffer.from(event.data.data).toString('utf-8');
}
} catch (err) {
// Ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the stringify should go in the catch next to the intent, and its safe to do it no matter what type it is.

Comment on lines 50 to 51
if ('data' in event && typeof event.data === 'object' && 'data' in event.data && Array.isArray(event.data.data)) {
raw = Buffer.from(event.data.data).toString('utf-8');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event.data should be an arraybuffer rather than an object containsing a array named data if im not mistaken websockets/ws#1222

@filfreire filfreire added this pull request to the merge queue Apr 24, 2023
Merged via the queue into Kong:develop with commit 47a1cea Apr 24, 2023
@filfreire filfreire deleted the feature/ins-2574-handle-binary-data-in-websockets branch April 24, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSocket Binary Message display as [object Object]
3 participants