diff options
author | Jaeseung Ha <ipknhama@gmail.com> | 2017-09-17 18:01:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-17 18:01:57 +0900 |
commit | ef17b8cb9b79921805f13f4947dadb07763ac475 (patch) | |
tree | 1f9c4ffe0dc004dc4cb648b2b58ac99c8b0dca79 /include/crow/websocket.h | |
parent | c63113f8250c3ef0eb4dfc25aeab7e2e7c475fc4 (diff) | |
parent | c43c052112cd15ac8be1d0cb90b6ad2570b2b99a (diff) | |
download | crow-ef17b8cb9b79921805f13f4947dadb07763ac475.tar.gz crow-ef17b8cb9b79921805f13f4947dadb07763ac475.zip |
Merge branch 'master' into master
Diffstat (limited to 'include/crow/websocket.h')
-rw-r--r-- | include/crow/websocket.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/include/crow/websocket.h b/include/crow/websocket.h index 3724375..d21d7e9 100644 --- a/include/crow/websocket.h +++ b/include/crow/websocket.h @@ -1,5 +1,6 @@ #pragma once #include <boost/algorithm/string/predicate.hpp> +#include <boost/array.hpp> #include "crow/socket_adaptors.h" #include "crow/http_request.h" #include "crow/TinySHA1.hpp" @@ -39,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")) { @@ -48,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"; @@ -486,6 +500,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_; }; } } |