BLWebSocketsServer
BLWebSocketsServer copied to clipboard
Safari closes connection on large messages with x-webkit-deflate-frame
I noticed today that sending large messages (e.g. 100.000 bytes) to a BLWebSocketsServer from a Safari browser (either iOS or Desktop) causes a close on the connection.
This behaviour does not happen with other browsers (e.g. Chrome) and stops immediately once I comment out the x-webkit-deflate-frame extension in extension.c
. I am not really a websocket expert and unsure if this is an issue with BLWebSocketsServer or with libwebsocket.
To test, you can create a simple echo server and then use this code (with adjusted IP and PORT):
<html>
<body>
<script>
function log(msg) {
document.getElementsByTagName("body")[0].innerHTML += msg+"<br/>";
}
var websocket = new WebSocket("ws://IP:PORT");
websocket.onopen = function() {
log("Open");
var x = "";
for( var i=0; i < 100000; i++ )
x += "x";
log("Sending "+x.length+" bytes.");
websocket.send(x);
};
websocket.onclose = function(e) {
log("Close ("+e.code+")");
};
</script>
</html>
The result in Chrome is:
Open
Sending 100000 bytes.
The result in Safari is:
Open
Sending 100000 bytes.
Close (1006)
This is probably related to libwebsocket.
I suppose so as well, still it might be better to disable the extension by default, as I pretty much only found the cause of the issue by accident, it's really hard to debug as Safari doesn't give any meaningful reason for closing the socket