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/websocket.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/websocket.h')
-rw-r--r-- | include/crow/websocket.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/include/crow/websocket.h b/include/crow/websocket.h index c03547c..efcf834 100644 --- a/include/crow/websocket.h +++ b/include/crow/websocket.h @@ -40,8 +40,10 @@ namespace crow 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<void(crow::websocket::connection&)> error_handler, + std::function<bool(const crow::request&)> accept_handler) : adaptor_(std::move(adaptor)), 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)) { if (!boost::iequals(req.get_header_value("upgrade"), "websocket")) { @@ -49,6 +51,17 @@ namespace crow delete this; return; } + + if (accept_handler_) + { + if (!accept_handler_(req)) + { + adaptor.close(); + delete this; + return; + } + } + // Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== // Sec-WebSocket-Version: 13 std::string magic = req.get_header_value("Sec-WebSocket-Key") + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; @@ -485,6 +498,7 @@ namespace crow 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_; }; } } |