diff options
author | P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com> | 2021-10-18 20:15:37 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-03-15 00:23:02 +0300 |
commit | a9f076e521433190bc526fa3eb4587090f48b909 (patch) | |
tree | 5b49b173502a85d1a7bd504a95a6f114b8b5230a /http/routing.hpp | |
parent | ad595fa64f619124eadcdfc2af259a1975136399 (diff) | |
download | bmcweb-a9f076e521433190bc526fa3eb4587090f48b909.tar.xz |
Add asyncResp support to handleUpgrade
This commit enables passing down the asyncResp (of the connection) to
the handler of upgraded connections. This is already in place for normal
requests (i.e. Class Router -> handle())
This change would enable any async calls that would be required before
upgrade of the connection. For example, as on today, we have only
Authentication of user in place for upgraded connection, but not
Authorization. So, this asyncResp could further be used for such dbus
calls to return informative response.
This commit updates the signature of all the handleUpgrade() functions
present in router.hpp to take in asyncResp object instead of normal
response.
Tested :
- websocket_test.py Passed
- KVM was functional in WebUI.
Change-Id: I1c6c91f126b734e1b5573d5ef204fe2bf6ed6c26
Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Diffstat (limited to 'http/routing.hpp')
-rw-r--r-- | http/routing.hpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/http/routing.hpp b/http/routing.hpp index 5ebc11fbf4..a85bd3ae59 100644 --- a/http/routing.hpp +++ b/http/routing.hpp @@ -55,19 +55,20 @@ class BaseRule virtual void handle(const Request& /*req*/, const std::shared_ptr<bmcweb::AsyncResp>&, const RoutingParams&) = 0; - virtual void handleUpgrade(const Request& /*req*/, Response& res, - boost::asio::ip::tcp::socket&& /*adaptor*/) + virtual void + handleUpgrade(const Request& /*req*/, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + boost::asio::ip::tcp::socket&& /*adaptor*/) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); } #ifdef BMCWEB_ENABLE_SSL virtual void handleUpgrade( - const Request& /*req*/, Response& res, + const Request& /*req*/, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&& /*adaptor*/) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); } #endif @@ -345,7 +346,8 @@ class WebSocketRule : public BaseRule asyncResp->res.result(boost::beast::http::status::not_found); } - void handleUpgrade(const Request& req, Response& /*res*/, + void handleUpgrade(const Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, boost::asio::ip::tcp::socket&& adaptor) override { BMCWEB_LOG_DEBUG << "Websocket handles upgrade"; @@ -358,7 +360,8 @@ class WebSocketRule : public BaseRule myConnection->start(); } #ifdef BMCWEB_ENABLE_SSL - void handleUpgrade(const Request& req, Response& /*res*/, + void handleUpgrade(const Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&& adaptor) override { @@ -1239,13 +1242,14 @@ class Router } template <typename Adaptor> - void handleUpgrade(const Request& req, Response& res, Adaptor&& adaptor) + void handleUpgrade(const Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + Adaptor&& adaptor) { std::optional<HttpVerb> verb = httpVerbFromBoost(req.method()); if (!verb || static_cast<size_t>(*verb) >= perMethods.size()) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } PerMethod& perMethod = perMethods[static_cast<size_t>(*verb)]; @@ -1259,8 +1263,7 @@ class Router { BMCWEB_LOG_DEBUG << "Cannot match rules " << req.url().encoded_path(); - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } @@ -1277,8 +1280,7 @@ class Router << req.methodString() << "(" << static_cast<uint32_t>(*verb) << ") / " << rules[ruleIndex]->getMethods(); - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } @@ -1289,14 +1291,14 @@ class Router // any uncaught exceptions become 500s try { - rules[ruleIndex]->handleUpgrade(req, res, + rules[ruleIndex]->handleUpgrade(req, asyncResp, std::forward<Adaptor>(adaptor)); } catch (const std::exception& e) { BMCWEB_LOG_ERROR << "An uncaught exception occurred: " << e.what(); - res.result(boost::beast::http::status::internal_server_error); - res.end(); + asyncResp->res.result( + boost::beast::http::status::internal_server_error); return; } catch (...) @@ -1304,8 +1306,8 @@ class Router BMCWEB_LOG_ERROR << "An uncaught exception occurred. The type was unknown " "so no information was available."; - res.result(boost::beast::http::status::internal_server_error); - res.end(); + asyncResp->res.result( + boost::beast::http::status::internal_server_error); return; } } |