From 27b0cf90f6cba207837f5c263a45c6ea5651975b Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Mon, 7 Aug 2023 12:02:40 -0700 Subject: Move to file_body in boost As is, it reads the whole file into memory before sending it. While fairly fast for the user, this wastes ram, and makes bmcweb less useful on less capable systems. This patch enables using the boost::beast::http::file_body type, which has more efficient serialization semantics than using a std::string. To do this, it adds a openFile() handler to http::Response, which can be used to properly open a file. Once the file is opened, the existing string body is ignored, and the file payload is sent instead. openFile() also returns success or failure, to allow users to properly handle 404s and other errors. To prove that it works, I moved over every instance of direct use of the body() method over to using this, including the webasset handler. The webasset handler specifically should help with system load when doing an initial page load of the webui. Tested: Redfish service validator passes. Change-Id: Ic7ea9ffefdbc81eb985de7edc0fac114822994ad Signed-off-by: Ed Tanous --- src/json_html_serializer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/json_html_serializer.cpp') diff --git a/src/json_html_serializer.cpp b/src/json_html_serializer.cpp index 405061beee..8322f1dd8a 100644 --- a/src/json_html_serializer.cpp +++ b/src/json_html_serializer.cpp @@ -562,8 +562,10 @@ void dumpHtml(std::string& out, const nlohmann::json& json) void prettyPrintJson(crow::Response& res) { - json_html_util::dumpHtml(res.body(), res.jsonValue); + std::string html; + json_html_util::dumpHtml(html, res.jsonValue); + res.write(std::move(html)); res.addHeader(boost::beast::http::field::content_type, "text/html;charset=UTF-8"); } -- cgit v1.2.3