summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2023-08-07 22:02:40 +0300
committerEd Tanous <ed@tanous.net>2023-10-31 20:43:04 +0300
commit27b0cf90f6cba207837f5c263a45c6ea5651975b (patch)
tree314cda7432edfe44fdd1297664db1399a1d6ba22 /src
parent522377dcb85082da598403e104a44d621b4c2bb4 (diff)
downloadbmcweb-27b0cf90f6cba207837f5c263a45c6ea5651975b.tar.xz
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 <ed@tanous.net>
Diffstat (limited to 'src')
-rw-r--r--src/json_html_serializer.cpp4
1 files changed, 3 insertions, 1 deletions
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");
}