summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-02-07 01:57:24 +0300
committerEd Tanous <ed@tanous.net>2024-04-14 20:56:40 +0300
commit4d69861ff74e6ab2543ffe8c015448c69222d91d (patch)
tree6dd08445c89cf6388928adf42cfdc24b2f7e8460 /http
parent8e8245db1812bb0ec294a1c9a97c3a65558840ed (diff)
downloadbmcweb-4d69861ff74e6ab2543ffe8c015448c69222d91d.tar.xz
Use beast message_generator
Beast 331 added the message_generator class, which allows deduplicating some templated code for the HTTP parser. When we use it, we can drop our binary size, and ensure that we have code reuse. This saves 2.2% on the compressed binary size. Tested: Redfish service validator passes. Change-Id: I5540d52dc256adfb62507c67ea642a9ea86d27ee Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'http')
-rw-r--r--http/http_client.hpp12
-rw-r--r--http/http_connection.hpp10
2 files changed, 11 insertions, 11 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 75304f69a1..6a20453b82 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -29,9 +29,9 @@
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/steady_timer.hpp>
-#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/flat_static_buffer.hpp>
#include <boost/beast/http/message.hpp>
+#include <boost/beast/http/message_generator.hpp>
#include <boost/beast/http/parser.hpp>
#include <boost/beast/http/read.hpp>
#include <boost/beast/http/write.hpp>
@@ -279,19 +279,19 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
// Set a timeout on the operation
timer.expires_after(std::chrono::seconds(30));
timer.async_wait(std::bind_front(onTimeout, weak_from_this()));
-
+ boost::beast::http::message_generator messageGenerator(std::move(req));
// Send the HTTP request to the remote host
if (sslConn)
{
- boost::beast::http::async_write(
- *sslConn, req,
+ boost::beast::async_write(
+ *sslConn, std::move(messageGenerator),
std::bind_front(&ConnectionInfo::afterWrite, this,
shared_from_this()));
}
else
{
- boost::beast::http::async_write(
- conn, req,
+ boost::beast::async_write(
+ conn, std::move(messageGenerator),
std::bind_front(&ConnectionInfo::afterWrite, this,
shared_from_this()));
}
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index 83645eeeb7..6ec8831f52 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -19,8 +19,10 @@
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/beast/_experimental/test/stream.hpp>
+#include <boost/beast/core/buffers_generator.hpp>
#include <boost/beast/core/flat_static_buffer.hpp>
#include <boost/beast/http/error.hpp>
+#include <boost/beast/http/message_generator.hpp>
#include <boost/beast/http/parser.hpp>
#include <boost/beast/http/read.hpp>
#include <boost/beast/http/write.hpp>
@@ -549,9 +551,9 @@ class Connection :
res.preparePayload();
startDeadline();
- serializer.emplace(res.response);
- boost::beast::http::async_write(
- adaptor, *serializer,
+ boost::beast::async_write(
+ adaptor,
+ boost::beast::http::message_generator(std::move(res.response)),
std::bind_front(&self_type::afterDoWrite, this,
shared_from_this()));
}
@@ -613,8 +615,6 @@ class Connection :
// Making this a std::optional allows it to be efficiently destroyed and
// re-created on Connection reset
std::optional<boost::beast::http::request_parser<bmcweb::HttpBody>> parser;
- std::optional<boost::beast::http::response_serializer<bmcweb::HttpBody>>
- serializer;
boost::beast::flat_static_buffer<8192> buffer;