stompjs icon indicating copy to clipboard operation
stompjs copied to clipboard

Ordering of protocol versions in ‘Sec-Websocket-Protocol’

Open mennolodder opened this issue 3 years ago • 7 comments

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: image

See: https://datatracker.ietf.org/doc/html/rfc6455#section-4.2.1

  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)

mennolodder avatar Aug 10 '21 14:08 mennolodder

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.

kum-deepak avatar Aug 10 '21 15:08 kum-deepak

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

kum-deepak avatar Aug 10 '21 15:08 kum-deepak

@mennolodder were you able to test this?

kum-deepak avatar Aug 27 '21 09:08 kum-deepak

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

mennolodder avatar Aug 27 '21 09:08 mennolodder

Many thanks! Based on your results I will make a minor release with this change.

kum-deepak avatar Aug 27 '21 09:08 kum-deepak

We've tested this and confirmed the protocol is then seletect as expected (on the websocket level)

mennolodder avatar Aug 31 '21 16:08 mennolodder

Thanks for confirming this. I will make a minor release with this change.

kum-deepak avatar Aug 31 '21 16:08 kum-deepak

Fixed by https://github.com/stomp-js/stompjs/commit/fb2f98edf5151aa707309595791315730e053d08

kum-deepak avatar Sep 01 '22 16:09 kum-deepak