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/http_connection.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/http_connection.hpp')
-rw-r--r-- | http/http_connection.hpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp index c28cde37ae..d5d02e545a 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -249,10 +249,21 @@ class Connection : thisReq.getHeaderValue(boost::beast::http::field::upgrade), "websocket")) { - handler->handleUpgrade(thisReq, res, std::move(adaptor)); - // delete lambda with self shared_ptr - // to enable connection destruction - asyncResp->res.setCompleteRequestHandler(nullptr); + asyncResp->res.setCompleteRequestHandler( + [self(shared_from_this())](crow::Response& thisRes) { + if (thisRes.result() != boost::beast::http::status::ok) + { + // When any error occurs before handle upgradation, + // the result in response will be set to respective + // error. By default the Result will be OK (200), + // which implies successful handle upgrade. Response + // needs to be sent over this connection only on + // failure. + self->completeRequest(thisRes); + return; + } + }); + handler->handleUpgrade(thisReq, asyncResp, std::move(adaptor)); return; } std::string_view expected = |