I am trying to enable the WebSocket-Extension permessage-deflate
in IIS 8, but with no luck so far. It seems, that IIS does not support any extensions and does not respond with an Sec-WebSockets-Extension
header.
I tried to send it manually via Response.Headers.Add("Sec-WebSockets-Extension", "permessage-deflate; client_no_context_takeover; server_no_context_takeover")
and did the compression/decompression via DeflateStream
by hand before sending/after receiving, but then the receive methods of the WebSocket failed.
I also tried to implement the WebSocket manually as an OWIN-Middleware (with the help of the library vtortola), but IIS keeps closing my InputStream
and reading of data is not possible.
Did anyone successfully enable this feature?
I am afraid it is not possible through System.Web.WebSockets
.
https://www.rfc-editor.org/rfc/rfc7692#section-6
Although you can indicate the HTTP headers for the deflate mode, the messages need to have activated the bit RSV1 in order to be identified as compressed:
This document allocates the RSV1 bit of the WebSocket header for PMCEs and calls the bit the "Per-Message Compressed" bit. On a WebSocket connection where a PMCE is in use, this bit indicates whether a message is compressed or not.
So even if you compress the payload, since the message header does not have the compression bit on, the receiver will still try to read as uncompressed. Once you negotiated the deflate mode through the HTTP upgrade mechanism, you can still send compressed and uncompressed messages together, and the reason for this is that deflate is not effective with small payloads, so there are messages that may not be worth to compress.
That said, since the WebSocket API in ASP.NET does not allow you to work out the message options, I am afraid this cannot be done.
Now, about OWIN. I have to say I have not explored this path, however, I doubt that is possible, at least integrated with IIS8 in the same port than HTTP, that is probably what you want to do.