server per message deflate support

This commit is contained in:
Benjamin Sergeant 2019-01-02 08:12:29 -08:00
parent 17270de621
commit b004769552

View File

@ -367,8 +367,8 @@ namespace ix
{ {
_enablePerMessageDeflate = false; _enablePerMessageDeflate = false;
} }
// Otherwise try to initialize the deflate engine (zlib)
if (!_perMessageDeflate.init(webSocketPerMessageDeflateOptions)) else if (!_perMessageDeflate.init(webSocketPerMessageDeflateOptions))
{ {
return WebSocketInitResult( return WebSocketInitResult(
false, 0,"Failed to initialize per message deflate engine"); false, 0,"Failed to initialize per message deflate engine");
@ -431,15 +431,30 @@ namespace ix
return WebSocketInitResult(false, 401, errorMsg); return WebSocketInitResult(false, 401, errorMsg);
} }
// FIXME perMessageDeflate support.
_enablePerMessageDeflate = false;
char output[29] = {}; char output[29] = {};
WebSocketHandshake::generate(headers["sec-websocket-key"].c_str(), output); WebSocketHandshake::generate(headers["sec-websocket-key"].c_str(), output);
std::stringstream ss; std::stringstream ss;
ss << "HTTP/1.1 101\r\n"; ss << "HTTP/1.1 101\r\n";
ss << "Sec-WebSocket-Accept: " << std::string(output) << "\r\n"; ss << "Sec-WebSocket-Accept: " << std::string(output) << "\r\n";
// Parse the client headers. Does it support deflate ?
std::string header = headers["sec-websocket-extensions"];
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(header);
// If the client has requested that extension, enable it.
if (webSocketPerMessageDeflateOptions.enabled())
{
_enablePerMessageDeflate = true;
if (!_perMessageDeflate.init(webSocketPerMessageDeflateOptions))
{
return WebSocketInitResult(
false, 0,"Failed to initialize per message deflate engine");
}
ss << webSocketPerMessageDeflateOptions.generateHeader();
}
ss << "\r\n"; ss << "\r\n";
if (!_socket->writeBytes(ss.str(), isCancellationRequested)) if (!_socket->writeBytes(ss.str(), isCancellationRequested))