Pass the max payload in Connection constructor

This commit is contained in:
oscar.chen 2022-05-15 01:01:24 -07:00
parent cdba76739f
commit a0a1925630
2 changed files with 4 additions and 5 deletions

View File

@ -391,13 +391,12 @@ namespace crow
void handle_upgrade(const request& req, response&, SocketAdaptor&& adaptor) override void handle_upgrade(const request& req, response&, SocketAdaptor&& adaptor) override
{ {
auto* conn = new crow::websocket::Connection<SocketAdaptor, App>(req, std::move(adaptor), app_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_); auto* conn = new crow::websocket::Connection<SocketAdaptor, App>(req, std::move(adaptor), max_payload_, max_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_);
conn->set_max_payload_size(max_payload_);
} }
#ifdef CROW_ENABLE_SSL #ifdef CROW_ENABLE_SSL
void handle_upgrade(const request& req, response&, SSLAdaptor&& adaptor) override void handle_upgrade(const request& req, response&, SSLAdaptor&& adaptor) override
{ {
new crow::websocket::Connection<SSLAdaptor, App>(req, std::move(adaptor), app_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_); new crow::websocket::Connection<SSLAdaptor, App>(req, std::move(adaptor), app_, max_payload_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_);
} }
#endif #endif

View File

@ -69,7 +69,7 @@ namespace crow
/// ///
/// Requires a request with an "Upgrade: websocket" header.<br> /// Requires a request with an "Upgrade: websocket" header.<br>
/// Automatically handles the handshake. /// Automatically handles the handshake.
Connection(const crow::request& req, Adaptor&& adaptor, Handler* handler, Connection(const crow::request& req, Adaptor&& adaptor, Handler* handler, uint64_t max_payload,
std::function<void(crow::websocket::connection&)> open_handler, std::function<void(crow::websocket::connection&)> open_handler,
std::function<void(crow::websocket::connection&, const std::string&, bool)> message_handler, std::function<void(crow::websocket::connection&, const std::string&, bool)> message_handler,
std::function<void(crow::websocket::connection&, const std::string&)> close_handler, std::function<void(crow::websocket::connection&, const std::string&)> close_handler,
@ -82,7 +82,7 @@ namespace crow
close_handler_(std::move(close_handler)), close_handler_(std::move(close_handler)),
error_handler_(std::move(error_handler)), error_handler_(std::move(error_handler)),
accept_handler_(std::move(accept_handler)), accept_handler_(std::move(accept_handler)),
max_payload_bytes_(handler->websocket_max_payload()) max_payload_bytes_(max_payload)
{ {
if (!boost::iequals(req.get_header_value("upgrade"), "websocket")) if (!boost::iequals(req.get_header_value("upgrade"), "websocket"))
{ {