summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/redfish-core/include/redfish_aggregator_test.cpp28
1 files changed, 14 insertions, 14 deletions
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<bmcweb::AsyncResp>();
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);