diff options
author | Ed Tanous <ed@tanous.net> | 2024-01-24 03:31:11 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-02-16 20:34:04 +0300 |
commit | 52e31629978bbcefc0e14c96272ef77c2dad6a9c (patch) | |
tree | e6618ffeeb0e0ab694a9484d4115344b8f767ff1 /http/http_request.hpp | |
parent | e4588158c0ccc2b3b7af459b262e8eaefaf8f985 (diff) | |
download | bmcweb-52e31629978bbcefc0e14c96272ef77c2dad6a9c.tar.xz |
Simplify body
Now that we have a custom boost http body class, we can use it in more
cases. There's some significant overhead and code when switching to a
file body, namely removing all the headers. Making the body class
support strings would allow us to completely avoid that inefficiency.
At the same time, it would mean that we can now use that class for all
cases, including HttpClient, and http::Request. This leads to some code
reduction overall, and means we're reliant on fewer beast structures.
As an added benefit, we no longer have to take a dependency on
boost::variant2.
Tested: Redfish service validator passes, with the exception of
badNamespaceInclude, which is showing warnings prior to this commit.
Change-Id: I061883a73230d6085d951c15891465c2c8445969
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'http/http_request.hpp')
-rw-r--r-- | http/http_request.hpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/http/http_request.hpp b/http/http_request.hpp index 7cefb7d912..9cd4a0c656 100644 --- a/http/http_request.hpp +++ b/http/http_request.hpp @@ -6,9 +6,9 @@ #include <boost/asio/io_context.hpp> #include <boost/asio/ip/address.hpp> #include <boost/beast/http/message.hpp> -#include <boost/beast/http/string_body.hpp> #include <boost/beast/websocket.hpp> #include <boost/url/url.hpp> +#include <http_file_body.hpp> #include <string> #include <string_view> @@ -19,7 +19,7 @@ namespace crow struct Request { - boost::beast::http::request<boost::beast::http::string_body> req; + boost::beast::http::request<bmcweb::FileBody> req; private: boost::urls::url urlBase{}; @@ -33,7 +33,7 @@ struct Request std::shared_ptr<persistent_data::UserSession> session; std::string userRole{}; - Request(boost::beast::http::request<boost::beast::http::string_body> reqIn, + Request(boost::beast::http::request<bmcweb::FileBody> reqIn, std::error_code& ec) : req(std::move(reqIn)) { @@ -65,6 +65,17 @@ struct Request req.insert(key, value); } + void clear() + { + req.clear(); + urlBase.clear(); + isSecure = false; + ioService = nullptr; + ipAddress = boost::asio::ip::address(); + session = nullptr; + userRole = ""; + } + boost::beast::http::verb method() const { return req.method(); @@ -102,7 +113,7 @@ struct Request const std::string& body() const { - return req.body(); + return req.body().str(); } bool target(std::string_view target) |