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_client.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_client.hpp')
-rw-r--r-- | http/http_client.hpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp index 076d852e90..6f42f3ef6e 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -33,7 +33,6 @@ #include <boost/beast/http/message.hpp> #include <boost/beast/http/parser.hpp> #include <boost/beast/http/read.hpp> -#include <boost/beast/http/string_body.hpp> #include <boost/beast/http/write.hpp> #include <boost/beast/ssl/ssl_stream.hpp> #include <boost/beast/version.hpp> @@ -117,10 +116,10 @@ struct ConnectionPolicy struct PendingRequest { - boost::beast::http::request<boost::beast::http::string_body> req; + boost::beast::http::request<bmcweb::FileBody> req; std::function<void(bool, uint32_t, Response&)> callback; PendingRequest( - boost::beast::http::request<boost::beast::http::string_body>&& reqIn, + boost::beast::http::request<bmcweb::FileBody>&& reqIn, const std::function<void(bool, uint32_t, Response&)>& callbackIn) : req(std::move(reqIn)), callback(callbackIn) @@ -139,8 +138,8 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> uint32_t connId; // Data buffers - http::request<http::string_body> req; - using parser_type = http::response_parser<http::string_body>; + http::request<bmcweb::FileBody> req; + using parser_type = http::response_parser<bmcweb::FileBody>; std::optional<parser_type> parser; boost::beast::flat_static_buffer<httpReadBufferSize> buffer; Response res; @@ -376,7 +375,7 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> { return; } - BMCWEB_LOG_DEBUG("recvMessage() data: {}", parser->get().body()); + BMCWEB_LOG_DEBUG("recvMessage() data: {}", parser->get().body().str()); unsigned int respCode = parser->get().result_int(); BMCWEB_LOG_DEBUG("recvMessage() Header Response Code: {}", respCode); @@ -669,7 +668,7 @@ class ConnectionPool : public std::enable_shared_from_this<ConnectionPool> return; } - auto nextReq = requestQueue.front(); + PendingRequest& nextReq = requestQueue.front(); conn.req = std::move(nextReq.req); conn.callback = std::move(nextReq.callback); @@ -734,12 +733,12 @@ class ConnectionPool : public std::enable_shared_from_this<ConnectionPool> const std::function<void(Response&)>& resHandler) { // Construct the request to be sent - boost::beast::http::request<boost::beast::http::string_body> thisReq( + boost::beast::http::request<bmcweb::FileBody> thisReq( verb, destUri.encoded_target(), 11, "", httpHeader); thisReq.set(boost::beast::http::field::host, destUri.encoded_host_address()); thisReq.keep_alive(true); - thisReq.body() = std::move(data); + thisReq.body().str() = std::move(data); thisReq.prepare_payload(); auto cb = std::bind_front(&ConnectionPool::afterSendData, weak_from_this(), resHandler); |