From d02a29f0ff33279268e675aae0856f3f8cf9d939 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 10 Jan 2023 14:22:47 +0100 Subject: Configurable Websocket für HTTPS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- https.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'https.cpp') diff --git a/https.cpp b/https.cpp index ce3a6fd..5d19d5b 100644 --- a/https.cpp +++ b/https.cpp @@ -56,13 +56,13 @@ class session : public std::enable_shared_from_this beast::flat_buffer buffer_; Server& m_server; std::optional> parser_; // need to reset parser every time, no other mechanism currently - http::request req_; + request_type req_; std::shared_ptr res_; // std::shared_ptr - void handle_request(::Server& server, request_type&& req) + void handle_request() { beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(300)); // timeout on write by server much longer than read timeout from client - auto sp = std::make_shared(generate_response(req, server)); + auto sp = std::make_shared(response::generate_response(req_, m_server)); res_ = sp; @@ -75,6 +75,13 @@ class session : public std::enable_shared_from_this shared_from_this(), sp->need_eof())); } + + void handle_websocket() + { + beast::get_lowest_layer(stream_).expires_never(); + std::make_shared(ioc_, std::move(stream_), response::get_websocket_address(req_, m_server))->do_accept_in(parser_->release()); + } + public: // Take ownership of the socket explicit @@ -171,13 +178,12 @@ public: if (websocket::is_upgrade(req_)) { - beast::get_lowest_layer(stream_).expires_never(); - std::make_shared(ioc_, std::move(stream_))->do_accept_in(parser_->release()); + handle_websocket(); return; } // Send the response - handle_request(m_server, std::move(req_)); + handle_request(); } void -- cgit v1.2.3