diff options
author | Jaeseung Ha <ipknhama@gmail.com> | 2017-09-17 14:17:46 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-17 14:17:46 +0900 |
commit | f0cb83df8808debab8dfcc5b53784385bc40b3ef (patch) | |
tree | f8c9a001f66b28e8396fccac580d855cd7f9a6c2 /include/crow/routing.h | |
parent | cf67a40e4c5e6ec0cacbc4ef5ecb063ff6e936e5 (diff) | |
parent | bea1ba3797fbf8bbab209edbbf765d0e6d5960d1 (diff) | |
download | crow-f0cb83df8808debab8dfcc5b53784385bc40b3ef.tar.gz crow-f0cb83df8808debab8dfcc5b53784385bc40b3ef.zip |
Merge pull request #210 from zxmarcos/master
Add onaccept handler to websocket rule
Diffstat (limited to 'include/crow/routing.h')
-rw-r--r-- | include/crow/routing.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/include/crow/routing.h b/include/crow/routing.h index 5d887e4..cdfa480 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -276,12 +276,12 @@ namespace crow void handle_upgrade(const request& req, response&, SocketAdaptor&& adaptor) override { - new crow::websocket::Connection<SocketAdaptor>(req, std::move(adaptor), open_handler_, message_handler_, close_handler_, error_handler_); + new crow::websocket::Connection<SocketAdaptor>(req, std::move(adaptor), open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_); } #ifdef CROW_ENABLE_SSL void handle_upgrade(const request& req, response&, SSLAdaptor&& adaptor) override { - new crow::websocket::Connection<SSLAdaptor>(req, std::move(adaptor), open_handler_, message_handler_, close_handler_, error_handler_); + new crow::websocket::Connection<SSLAdaptor>(req, std::move(adaptor), open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_); } #endif @@ -313,11 +313,19 @@ namespace crow return *this; } + template <typename Func> + self_t& onaccept(Func f) + { + accept_handler_ = f; + return *this; + } + protected: 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&)> close_handler_; std::function<void(crow::websocket::connection&)> error_handler_; + std::function<bool(const crow::request&)> accept_handler_; }; template <typename T> |