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

Option to change how websocket data frames are returned to the client #39

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

Eligioo
Copy link
Member

@Eligioo Eligioo commented Jan 23, 2025

The websocket specification defines 2 ways how application-layer data transmitted over the socket can be represented: Text or Binary. Currently the default data frame representation returned by the RPC server is Binary but this is counterintuitive since JSONRPC already is in a text representation.

This PR let the client, per connection, decide in which representation data should be returned by the server. This is achived by adding support for a frame query parameter on the /ws endpoint. Examples:

  • ws://127.0.0.1:8000/ws --> data frames are returned as Binary (default)
  • ws://127.0.0.1:8000/ws?frame=text --> data frames are returned as Text
  • ws://127.0.0.1:8000/ws?frame=binary --> data frames are returned as Binary
  • ws://127.0.0.1:8000/ws?frame=foo --> data frames are returned as Binary (Fallback for unsupported values)

To accomplish backwards compatibility Binary is still the default returned representation but in a major release this should be changed to Text

@Eligioo Eligioo requested review from jsdanielh and hrxi January 23, 2025 12:26
@hrxi
Copy link
Contributor

hrxi commented Jan 23, 2025

CC nimiq/core-rs-albatross#3236

@Eligioo Eligioo force-pushed the stefan/websocket-text-frames branch from 9ae342d to e5c81ae Compare January 23, 2025 12:47
Copy link
Member

@jsdanielh jsdanielh left a comment

Choose a reason for hiding this comment

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

LGTM

@jsdanielh jsdanielh force-pushed the stefan/websocket-text-frames branch from e5c81ae to 6656e4c Compare January 27, 2025 23:49
The websocket specification defines 2 ways how application-layer data transmitted over the socket can be represented: `Text` or `Binary`.
Currently the default data frame representation returned by the RPC server is `Binary` but this is counterintuitive since JSONRPC already is in a text representation.

This PR let the client, per connection, decide in which representation data should be returned by the server. This is achived by adding support for a `frame` query parameter on the `/ws` endpoint.
Examples:
- ws://127.0.0.1:8000/ws		--> data frames are returned as `Binary` (default)
- ws://127.0.0.1:8000/ws?frame=text	--> data frames are returned as `Text`
- ws://127.0.0.1:8000/ws?frame=binary	--> data frames are returned as `Binary`
- ws://127.0.0.1:8000/ws?frame=foo   	--> data frames are returned as `Binary` (Fallback for unsupported values)

To accomplish backwards compatibility `Binary` is still the default returned representation but in a major release this should be changed to `Text`
@jsdanielh jsdanielh force-pushed the stefan/websocket-text-frames branch from 6656e4c to ae65618 Compare January 27, 2025 23:50
@jsdanielh jsdanielh merged commit ae65618 into master Jan 28, 2025
7 checks passed
@jsdanielh jsdanielh deleted the stefan/websocket-text-frames branch January 28, 2025 19:55
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.

3 participants