• Robert Knight's avatar
    Specify status code when closing WebSocket connection from the client · fdedc956
    Robert Knight authored
    Fix browser warnings about an abnormal disconnection when the WS
    connection is closed normally by calling `socket.close()`.
    
    When `WebSocket#close` is called with no code, the browser will send a
    close frame to the server with no payload. This is valid. On the backend
    ws4py translates this into a 1005 status code, which is also correct.
    However, ws4py then responds with the server's close frame and instead
    of sending no payload, it sends a close frame with a payload that has a
    1005 status. This is not allowed by the spec and results in errors in
    the browser about an abnormal disconnection.
    
    Although the proper fix for this needs to happen on the server, the
    simplest solution right now is to set a status code in the client and
    ws4py will respond with the same status code in the server's close
    frame.
    
    As part of this, refactor the tests to clearly separate the tests for
    what happens when the browser/server closes the connection vs when the
    client closes the connection.
    fdedc956
websocket-test.js 3.48 KB