JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

Potential Stomp/Chrome compatibility issue: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received #8

Closed shogunpurple closed 8 years ago

shogunpurple commented 8 years ago

It seems like the latest version of Chrome has broken my websocket functionality in my application. I am utilising the following code to use Stomp with a SockJS websocket.

import SockJS from 'sockjs-client';
import Stomp from 'webstomp-client';

class WebSocket {

    static register(registrations, endpoint) {
        var socket = SockJS(endpoint);
        var stompClient = Stomp.over(socket);
        stompClient.connect({}, (frame) => {
            console.log('Connected: ' + frame);
            registrations.forEach(function (registration) {
                stompClient.subscribe(registration.route, registration.callback);
            });
        });
    }
}

export default WebSocket;

I am using spring boot in the backend which is also unchanged. I assumed that using Stomp.over would not send that header (or some sort of default one), and it has been working fine for a long time without sending the response header from the server for the subprotocol. I cannot see any 'Sec-WebSocket-Protocol' header in the dev tools either. Any ideas what may have happened here?

Thanks.

JSteunou commented 8 years ago

It is in Chrome for a while and it respects the protocol. Your server should return a non empty header. It's a server issue. See the same on rabbitmq https://github.com/rabbitmq/rabbitmq-web-stomp/issues/53 It might be SockJS or your server that had been updated.

See if you can fix the server, or else you would have to cheat on client side by sending empty protocols. I do not know how this can be set using SockJS, but you can definitely set it using native WebSocket https://github.com/JSteunou/webstomp-client/blob/master/src/webstomp.js#L9

shogunpurple commented 8 years ago

Ok, thanks. I cannot see the header in the dev tools so I can match it up with the server. Do you know the default protocol set with Stomp.over so I can configure my server to respond appropriately?

JSteunou commented 8 years ago

Nope I dont. Because it's not this lib who's sending the protocol. It's the WebSocket object or your over layer, in your case SockJS. Look at the link I posted above.