Fixed small bugs in code

This commit is contained in:
The-EDev 2022-05-16 19:14:51 +03:00
parent 3969d5f644
commit 57c3b43ac0
No known key found for this signature in database
GPG Key ID: 51C45DC0C413DCD9
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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<SocketAdaptor, App>(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<typename Func>
@ -448,6 +452,7 @@ namespace crow
std::function<void(crow::websocket::connection&)> error_handler_;
std::function<bool(const crow::request&)> accept_handler_;
uint64_t max_payload_;
bool max_payload_override_ = false;
};
/// Allows the user to assign parameters using functions.

View File

@ -77,12 +77,12 @@ namespace crow
std::function<bool(const crow::request&)> 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"))
{