diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-10 14:22:47 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-10 14:22:47 +0100 |
commit | d02a29f0ff33279268e675aae0856f3f8cf9d939 (patch) | |
tree | bbb22aeb9c14488ef0871b34f0400259658d46f0 /https.cpp | |
parent | 1191f07767583a9b19280a4f29cb1b0bd6799785 (diff) |
Configurable Websocket für HTTPS
Diffstat (limited to 'https.cpp')
-rw-r--r-- | https.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -56,13 +56,13 @@ class session : public std::enable_shared_from_this<session> beast::flat_buffer buffer_; Server& m_server; std::optional<http::request_parser<http::string_body>> parser_; // need to reset parser every time, no other mechanism currently - http::request<http::string_body> req_; + request_type req_; std::shared_ptr<response_type> res_; // std::shared_ptr<void> - 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<response_type>(generate_response(req, server)); + auto sp = std::make_shared<response_type>(response::generate_response(req_, m_server)); res_ = sp; @@ -75,6 +75,13 @@ class session : public std::enable_shared_from_this<session> shared_from_this(), sp->need_eof())); } + + void handle_websocket() + { + beast::get_lowest_layer(stream_).expires_never(); + std::make_shared<websocket_session>(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<websocket_session>(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 |