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>
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 076d852..6f42f3e 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 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 @@
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 @@
{
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 @@
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 @@
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);