diff options
author | Jonathan Doman <jonathan.doman@intel.com> | 2024-04-16 02:56:23 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-05-03 18:24:02 +0300 |
commit | 102a4cdacb0a6d8c8c3c97e10bedbb66000ac5dc (patch) | |
tree | 56eef176e8bd7446995556b90c8216e4a88a701e /http/http_request.hpp | |
parent | 1aa375b80075c7e1acdc9188440a62bab21b8651 (diff) | |
download | bmcweb-102a4cdacb0a6d8c8c3c97e10bedbb66000ac5dc.tar.xz |
Manage Request with shared_ptr
This is an attempt to solve a class of use-after-move bugs on the
Request objects which have popped up several times. This more clearly
identifies code which owns the Request objects and has a need to keep it
alive. Currently it's just the `Connection` (or `HTTP2Connection`)
(which needs to access Request headers while sending the response), and
the `validatePrivilege()` function (which needs to temporarily own the
Request while doing an asynchronous D-Bus call). Route handlers are
provided a non-owning `Request&` for immediate use and required to not
hold the `Request&` for future use.
Tested: Redfish validator passes (with a few unrelated fails).
Redfish URLs are sent to a browser as HTML instead of raw JSON.
Change-Id: Id581fda90b6bceddd08a5dc7ff0a04b91e7394bf
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'http/http_request.hpp')
-rw-r--r-- | http/http_request.hpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/http/http_request.hpp b/http/http_request.hpp index d1a6ac053a..d2a1e259fc 100644 --- a/http/http_request.hpp +++ b/http/http_request.hpp @@ -18,7 +18,8 @@ namespace crow struct Request { - boost::beast::http::request<bmcweb::HttpBody> req; + using Body = boost::beast::http::request<bmcweb::HttpBody>; + Body req; private: boost::urls::url urlBase; @@ -32,9 +33,7 @@ struct Request std::shared_ptr<persistent_data::UserSession> session; std::string userRole; - Request(boost::beast::http::request<bmcweb::HttpBody> reqIn, - std::error_code& ec) : - req(std::move(reqIn)) + Request(Body reqIn, std::error_code& ec) : req(std::move(reqIn)) { if (!setUrlInfo()) { |