Using AsyncResp everywhere
Get the core using AsyncResp everywhere, and not have each individual handler
creating its own object.We can call app.handle() without fear of the response
getting ended after the first tree is done populating.
Don't use res.end() anymore.
Tested:
1. Validator passed.
Signed-off-by: zhanghaicheng <zhanghch05@inspur.com>
Change-Id: I867367ce4a0caf8c4b3f4e07e06c11feed0782e8
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 97a0194..070442e 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -143,16 +143,18 @@
}
app.routeDynamic(webpath)(
- [absolutePath, contentType,
- contentEncoding](const crow::Request&, crow::Response& res) {
+ [absolutePath, contentType, contentEncoding](
+ const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
if (contentType != nullptr)
{
- res.addHeader("Content-Type", contentType);
+ asyncResp->res.addHeader("Content-Type", contentType);
}
if (contentEncoding != nullptr)
{
- res.addHeader("Content-Encoding", contentEncoding);
+ asyncResp->res.addHeader("Content-Encoding",
+ contentEncoding);
}
// res.set_header("Cache-Control", "public, max-age=86400");
@@ -160,15 +162,14 @@
if (!inf)
{
BMCWEB_LOG_DEBUG << "failed to read file";
- res.result(
+ asyncResp->res.result(
boost::beast::http::status::internal_server_error);
- res.end();
return;
}
- res.body() = {std::istreambuf_iterator<char>(inf),
- std::istreambuf_iterator<char>()};
- res.end();
+ asyncResp->res.body() = {
+ std::istreambuf_iterator<char>(inf),
+ std::istreambuf_iterator<char>()};
});
}
}