SockJS framing #556
Replies: 5 comments
-
Interesting change indeed - I'd go with Also, where do you see this change? version 1.1? version 2.0? Thanks, |
Beta Was this translation helpful? Give feedback.
-
In my test code I've just been using This change would definitely increment the major version number. |
Beta Was this translation helpful? Give feedback.
-
I proposed something similar like this for the Caplin Liberator protocol a long time ago. It would be feasible for all projects I have seen. |
Beta Was this translation helpful? Give feedback.
-
When revising the framing, perhaps the concept of a 'continuation frame'('fragmentation') can also be added. |
Beta Was this translation helpful? Give feedback.
-
i think if this's a pure lib, you should't change send data even if data is not support. |
Beta Was this translation helpful? Give feedback.
-
I want to start a discussion around SockJS protocol framing. Currently everything gets JSON encoded, even if it is already a string. This leads to double escaping of objects that were JSON stringified already (primus/primus#79). The WebSocket
send
method takes a string parameter, and it shouldn't be manipulating it more than necessary.I could rectify just this part, but it would most likely be solved by having all messages be a JSON object. Because older browsers having missing/broken JSON.parse/stringify implementations, it requires us to use a polyfill (currently JSON3). This is slow on those same older browsers, and increases the size of the library quite significantly.
Ideally no framing would be necessary. We do need purpose frames like
heartbeat
,open
, andclose
though. We could make those very specific strings, like say__sockjs_o__
, and treat everything else like a user message. The only caveat is we need a way to send multiple messages in a single request/response for optimal use of polling transports. Those messages need to be delimited by something. Currently\n
is used for some transports, JSON-encoded arrays for others. This doesn't cause issues with user content that contains newlines because they are escaped. But if extra escaping was stopped, then they would. Newlines (specifically\r\n
) also has a special meaning for the SSE transport, so they have to be escaped there as well.We could use specific unicode characters (
US
decimal 31 andRS
decimal 30, http://en.wikipedia.org/wiki/C0_and_C1_control_codes#Field_separators) for delimiters, but that would prevent user messages from containing them. I think this is a much lower probability than a newline. This also lets us delimit at multiple levels. For example, between frame type and frame data by using US, and between multiple user messages by RS.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions