diff options
author | eidheim <eidheim@gmail.com> | 2020-08-08 11:40:44 +0300 |
---|---|---|
committer | eidheim <eidheim@gmail.com> | 2020-08-08 11:41:04 +0300 |
commit | d1d6b015172731902c88bcd2c7fe064c55605844 (patch) | |
tree | 331215674f356871cbf0d64a613ff47c09dfc9df /server_ws.hpp | |
parent | 95cefd438f06dab3ef2c501c0d1f1105121ce305 (diff) |
Cleanup of Connection::remote_endpoint_address and Connection::remote_endpoint_port as suggested in !108, moved read of endpoint before on_hanshake call in write_handshake, and added Connection::local_endpoint as in commit https://gitlab.com/eidheim/Simple-Web-Server/-/commit/8e82428740c0d6b9126480f816178fc404bfd4ec.
Diffstat (limited to 'server_ws.hpp')
-rw-r--r-- | server_ws.hpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/server_ws.hpp b/server_ws.hpp index 6af4384..158813d 100644 --- a/server_ws.hpp +++ b/server_ws.hpp @@ -91,10 +91,20 @@ namespace SimpleWeb { return endpoint; } + asio::ip::tcp::endpoint local_endpoint() const noexcept { + try { + if(auto connection = this->connection.lock()) + return connection->socket->lowest_layer().local_endpoint(); + } + catch(...) { + } + return asio::ip::tcp::endpoint(); + } + /// Deprecated, please use remote_endpoint().address().to_string() instead. DEPRECATED std::string remote_endpoint_address() const noexcept { try { - return socket->lowest_layer().remote_endpoint().address().to_string(); + return endpoint.address().to_string(); } catch(...) { } @@ -104,7 +114,7 @@ namespace SimpleWeb { /// Deprecated, please use remote_endpoint().port() instead. DEPRECATED unsigned short remote_endpoint_port() const noexcept { try { - return socket->lowest_layer().remote_endpoint().port(); + return endpoint.port(); } catch(...) { } @@ -530,12 +540,6 @@ namespace SimpleWeb { } void write_handshake(const std::shared_ptr<Connection> &connection) { - try { - connection->endpoint = connection->socket->lowest_layer().remote_endpoint(); - } - catch (...) { - } - for(auto ®ex_endpoint : endpoint) { regex::smatch path_match; if(regex::regex_match(connection->path, path_match, regex_endpoint.first)) { @@ -554,6 +558,12 @@ namespace SimpleWeb { auto sha1 = Crypto::sha1(key_it->second + ws_magic_string); response_header.emplace("Sec-WebSocket-Accept", Crypto::Base64::encode(sha1)); + try { + connection->endpoint = connection->socket->lowest_layer().remote_endpoint(); + } + catch(...) { + } + if(regex_endpoint.second.on_handshake) status_code = regex_endpoint.second.on_handshake(connection, response_header); |