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 --- .../include/redfish_aggregator_test.cpp | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/redfish-core/include/redfish_aggregator_test.cpp b/test/redfish-core/include/redfish_aggregator_test.cpp index 83e4b4ec23..26015f7096 100644 --- a/test/redfish-core/include/redfish_aggregator_test.cpp +++ b/test/redfish-core/include/redfish_aggregator_test.cpp @@ -248,8 +248,8 @@ void assertProcessResponse(unsigned result) jsonResp["Name"] = "Test"; crow::Response resp; - resp.body() = jsonResp.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write( + jsonResp.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); resp.addHeader("Content-Type", "application/json"); resp.addHeader("Allow", "GET"); resp.addHeader("Location", "/redfish/v1/Chassis/TestChassis"); @@ -351,8 +351,8 @@ void populateCollectionNotFound(crow::Response& resp) // from a satellite which will not have a json component void convertToSat(crow::Response& resp) { - resp.body() = resp.jsonValue.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write(resp.jsonValue.dump(2, ' ', true, + nlohmann::json::error_handler_t::replace)); resp.jsonValue.clear(); } @@ -494,7 +494,7 @@ TEST(processCollectionResponse, preserveHeaders) void assertProcessResponseContentType(std::string_view contentType) { crow::Response resp; - resp.body() = "responseBody"; + resp.write("responseBody"); resp.addHeader("Content-Type", contentType); resp.addHeader("Location", "/redfish/v1/Chassis/TestChassis"); resp.addHeader("Link", "metadataLink"); @@ -507,7 +507,7 @@ void assertProcessResponseContentType(std::string_view contentType) "/redfish/v1/Chassis/prefix_TestChassis"); EXPECT_EQ(asyncResp->res.getHeaderValue("Link"), ""); EXPECT_EQ(asyncResp->res.getHeaderValue("Retry-After"), "120"); - EXPECT_EQ(asyncResp->res.body(), "responseBody"); + EXPECT_EQ(*asyncResp->res.body(), "responseBody"); } TEST(processResponse, DifferentContentType) @@ -658,8 +658,8 @@ TEST(processContainsSubordinateResponse, addLinks) jsonValue["Test"]["@odata.id"] = "/redfish/v1/Test"; jsonValue["TelemetryService"]["@odata.id"] = "/redfish/v1/TelemetryService"; jsonValue["UpdateService"]["@odata.id"] = "/redfish/v1/UpdateService"; - resp.body() = jsonValue.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write( + jsonValue.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); auto asyncResp = std::make_shared(); asyncResp->res.result(200); @@ -701,8 +701,8 @@ TEST(processContainsSubordinateResponse, localNotOK) jsonValue["Test"]["@odata.id"] = "/redfish/v1/Test"; jsonValue["TelemetryService"]["@odata.id"] = "/redfish/v1/TelemetryService"; jsonValue["UpdateService"]["@odata.id"] = "/redfish/v1/UpdateService"; - resp.body() = jsonValue.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write( + jsonValue.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); RedfishAggregator::processContainsSubordinateResponse("prefix", asyncResp, resp); @@ -769,8 +769,8 @@ TEST(processContainsSubordinateResponse, noValidLinks) nlohmann::json jsonValue; resp.addHeader("Content-Type", "application/json"); jsonValue["@odata.id"] = "/redfish/v1"; - resp.body() = jsonValue.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write( + jsonValue.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); RedfishAggregator::processContainsSubordinateResponse("prefix", asyncResp, resp); @@ -788,8 +788,8 @@ TEST(processContainsSubordinateResponse, noValidLinks) jsonValue["Test"]["@odata.id"] = "/redfish/v1/Test"; jsonValue["TelemetryService"]["@odata.id"] = "/redfish/v1/TelemetryService"; jsonValue["UpdateService"]["@odata.id"] = "/redfish/v1/UpdateService"; - resp.body() = jsonValue.dump(2, ' ', true, - nlohmann::json::error_handler_t::replace); + resp.write( + jsonValue.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); RedfishAggregator::processContainsSubordinateResponse("prefix", asyncResp, resp); -- cgit v1.2.3