stompjs
stompjs copied to clipboard
Ordering of protocol versions in ‘Sec-Websocket-Protocol’
When debugging our connection using Stomp (to our Spring stomp service) I've noticed the following:
The http header Sec-Websocket-Protocol lists the supported protocols in ascending order starting with 1.0. However the websocket spec states it needs to be in order of preference. Example:
See: https://datatracker.ietf.org/doc/html/rfc6455#section-4.2.1
- Optionally, a |Sec-WebSocket-Protocol| header field, with a list of values indicating which protocols the client would like to speak, ordered by preference.
The spring server supports all, so replies with the preferred version (1.0). See also this ticket (about something else) that discusses it: https://github.com/spring-projects/spring-framework/issues/21792#issuecomment-453476940
As the actual stomp protocol over the websocket also negotiates the protocol, they actually select 1.2 setting up the 1.0 connection. (although it did freak me out initially).
Im using stomp js version 6.1.0 (through ng2-stompjs)
Thanks for pointing it out. Interesting to see that WebSocket and STOMP specs take different approaches for the same underlying thing (https://stomp.github.io/stomp-specification-1.2.html#Protocol_Negotiation).
Your help in testing the solution out will be highly appreciated. The list of versions is configurable - https://stomp-js.github.io/api-docs/latest/classes/Client.html#stompVersions and https://stomp-js.github.io/api-docs/latest/classes/StompConfig.html#stompVersions. Please try setting it
// either directly on the client or via configuration
// The default is ['1.0', '1.1', '1.2']
client.stompVersions = new Versions(['1.2', '1.1', '1.0']);
If this corrects the issue, we can make it the default order.
In ng2-stompjs
you would need to set it through configuration. The above example will only work for stompjs
. https://stomp-js.github.io/api-docs/latest/classes/RxStompConfig.html#stompVersions
@mennolodder were you able to test this?
Sorry was on holiday when you requested it. Asked a colleague but it didn't come through, have placed it on the to-do list again
Many thanks! Based on your results I will make a minor release with this change.
We've tested this and confirmed the protocol is then seletect as expected (on the websocket level)
Thanks for confirming this. I will make a minor release with this change.
Fixed by https://github.com/stomp-js/stompjs/commit/fb2f98edf5151aa707309595791315730e053d08