From 57c3b43ac01fe362ba0afb2e1069692e21d6dd60 Mon Sep 17 00:00:00 2001 From: The-EDev Date: Mon, 16 May 2022 19:14:51 +0300 Subject: [PATCH] Fixed small bugs in code --- include/crow/app.h | 1 + include/crow/routing.h | 11 ++++++++--- include/crow/websocket.h | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 342cbe55a..88a74a57a 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -107,6 +107,7 @@ namespace crow self_t& websocket_max_payload(uint64_t max_payload) { max_payload_ = max_payload; + return *this; } /// Get the default max payload size for websockets diff --git a/include/crow/routing.h b/include/crow/routing.h index 3cb1ba1dd..b44c3228b 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -377,7 +377,7 @@ namespace crow WebSocketRule(std::string rule, App* app): BaseRule(std::move(rule)), app_(app), - max_payload_(app_->websocket_max_payload()) + max_payload_(UINT64_MAX) {} void validate() override @@ -391,6 +391,7 @@ namespace crow void handle_upgrade(const request& req, response&, SocketAdaptor&& adaptor) override { + max_payload_ = max_payload_override_ ? max_payload_ : app_->websocket_max_payload(); new crow::websocket::Connection(req, std::move(adaptor), app_, max_payload_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_); } #ifdef CROW_ENABLE_SSL @@ -400,9 +401,12 @@ namespace crow } #endif - self_t& maxpayload(uint64_t payload) + /// Override the global payload limit for this single WebSocket rule + self_t& max_payload(uint64_t max_payload) { - max_payload_ = payload; + max_payload_ = max_payload; + max_payload_override_ = true; + return *this; } template @@ -448,6 +452,7 @@ namespace crow std::function error_handler_; std::function accept_handler_; uint64_t max_payload_; + bool max_payload_override_ = false; }; /// Allows the user to assign parameters using functions. diff --git a/include/crow/websocket.h b/include/crow/websocket.h index 43c7e6cec..bbea07a62 100644 --- a/include/crow/websocket.h +++ b/include/crow/websocket.h @@ -77,12 +77,12 @@ namespace crow std::function accept_handler): adaptor_(std::move(adaptor)), handler_(handler), + max_payload_bytes_(max_payload), open_handler_(std::move(open_handler)), message_handler_(std::move(message_handler)), close_handler_(std::move(close_handler)), error_handler_(std::move(error_handler)), - accept_handler_(std::move(accept_handler)), - max_payload_bytes_(max_payload) + accept_handler_(std::move(accept_handler)) { if (!boost::iequals(req.get_header_value("upgrade"), "websocket")) {