MediaBrowser / SocketHttpListener

A standalone HttpListener with support for SSL, WebSockets and Mono
MIT License
42 stars 14 forks source link

Fixed Websocket problem with latest Firefox versions #8

Closed softworkz closed 9 years ago

softworkz commented 9 years ago

The latest Firefox versions (>=37) are using permessage compression. The current implementation of permessage compression in websocket-sharp is incorrect because it creates a new DeflateStream object for every message, but this is only allowed, if client_no_context_takeover or server_no_context_takeover has been agreed during the handshake. Otherwise the DeflateStream object would need to be persisted and reused for each connection, in order to implement the LZ77 sliding window.

I tried to copy over some stuff from websocket-sharp, to include client_no_context_takeover and server_no_context_takeover, but that does not have any effect on the Firefox behaviour. According to the spec, the server may just acknowledge the extensions requested by the client, but may not add options (like client_no_context_takeover). As a consequence, this didn't solve the problem.

The final solution would of course be to change the code to reuse the DeflateStream objects, but it hasn't even been done in webbsocket-sharp. Instead websocket-sharp has introduced an IgnoreExtensions property which effectively disables lines 163-165 in WebSocket.cs. I have commented these out in our code as a quick fix. As a result permessage compression is simply disabled.

This change finally made Emby-Websockets on Firefox clients work again!

LukePulverenti commented 9 years ago

Excellent, thanks! Really glad to see this one fixed.

softworkz commented 9 years ago

Some further reading:

https://bugzilla.mozilla.org/show_bug.cgi?id=1176176 https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/ https://github.com/sta/websocket-sharp/issues/132 https://github.com/sta/websocket-sharp/issues/140

softworkz commented 9 years ago

Wow, that was a quick merge :-) PS: Closes MediaBrowser/Emby#1194

softworkz commented 9 years ago

Actually this also closes MediaBrowser/Emby#1193