From 6befbd4a379da0bd8567d842facae8b3bf436722 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sat, 29 Dec 2018 14:00:26 +0100 Subject: [PATCH] Allow UWS_NO_ZLIB to work properly --- misc/main.cpp | 4 ++-- src/App.h | 5 +++++ src/PerMessageDeflate.h | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/misc/main.cpp b/misc/main.cpp index e6664d3..cf3b651 100644 --- a/misc/main.cpp +++ b/misc/main.cpp @@ -10,7 +10,7 @@ int main(int argc, char **argv) { int hello; }; - uWS::SSLApp({ + uWS::/*SSL*/App({ .key_file_name = "/home/alexhultman/key.pem", .cert_file_name = "/home/alexhultman/cert.pem", .passphrase = "1234" @@ -19,7 +19,7 @@ int main(int argc, char **argv) { }).ws("/*", { /* Settings */ .compression = uWS::DEDICATED_COMPRESSOR, - .maxPayloadLength = 16 * 1024, + .maxPayloadLength = 16 * 1024 * 1024, /* Handlers */ .open = [](auto *ws, auto *req) { std::cout << "WebSocket connected" << std::endl; diff --git a/src/App.h b/src/App.h index b15efbb..7afbaa4 100644 --- a/src/App.h +++ b/src/App.h @@ -78,6 +78,11 @@ public: /* Every route has its own websocket context with its own behavior and user data type */ auto *webSocketContext = WebSocketContext::create(Loop::defaultLoop(), (typename StaticDispatch::SOCKET_CONTEXT_TYPE *) httpContext); + /* Quick fix to disable any compression if set */ +#ifdef UWS_NO_ZLIB + behavior.compression = uWS::DISABLED; +#endif + /* If we are the first one to use compression, initialize it */ if (behavior.compression) { LoopData *loopData = (LoopData *) us_loop_ext(static_dispatch(us_ssl_socket_context_loop, us_socket_context_loop)(webSocketContext->getSocketContext())); diff --git a/src/PerMessageDeflate.h b/src/PerMessageDeflate.h index fc60ee8..1f6b0f4 100644 --- a/src/PerMessageDeflate.h +++ b/src/PerMessageDeflate.h @@ -19,7 +19,19 @@ #ifndef PERMESSAGEDEFLATE_H #define PERMESSAGEDEFLATE_H /* Do not compile this module if we don't want it */ -#ifndef UWS_NO_ZLIB +#ifdef UWS_NO_ZLIB +struct ZlibContext {}; +struct InflationStream { + std::string_view inflate(ZlibContext *zlibContext, std::string_view compressed, size_t maxPayloadLength) { + return compressed; + } +}; +struct DeflationStream { + std::string_view deflate(ZlibContext *zlibContext, std::string_view raw, bool reset) { + return raw; + } +}; +#else #include @@ -109,6 +121,10 @@ struct InflationStream { inflateInit2(&inflationStream, -15); } + ~InflationStream() { + std::cout << "Destructing inflationstream" << std::endl; + } + std::string_view inflate(ZlibContext *zlibContext, std::string_view compressed, size_t maxPayloadLength) { /* We clear this one here, could be done better */