From fff40952a3647a30095ed1e55a5a2e34d2cbd06b Mon Sep 17 00:00:00 2001 From: An Tao Date: Wed, 11 Sep 2019 15:14:40 +0800 Subject: [PATCH] Modify the method to generate the 404 page (#240) --- lib/inc/drogon/NotFound.h | 8 +++++++- lib/src/HttpResponseImpl.cc | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/inc/drogon/NotFound.h b/lib/inc/drogon/NotFound.h index b9b4bbbb..e4777cea 100644 --- a/lib/inc/drogon/NotFound.h +++ b/lib/inc/drogon/NotFound.h @@ -15,7 +15,12 @@ */ #include - +namespace drogon +{ +/** + * @brief This class is used by the drogon to generate the 404 page. Users don't + * use this class directly. + */ class NotFound : public drogon::DrTemplate { public: @@ -23,3 +28,4 @@ class NotFound : public drogon::DrTemplate virtual ~NotFound(){}; virtual std::string genText(const drogon::HttpViewData &) override; }; +} // namespace drogon diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index a71e5727..b0e2403b 100644 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -78,8 +78,13 @@ HttpResponsePtr HttpResponse::newNotFoundResponse() std::call_once(once, []() { HttpViewData data; data.insert("version", getVersion()); - notFoundResp = HttpResponse::newHttpViewResponse("NotFound", data); + notFoundResp = + HttpResponse::newHttpViewResponse("drogon::NotFound", data); notFoundResp->setStatusCode(k404NotFound); + notFoundResp->setExpiredTime(0); + auto str = static_cast(notFoundResp.get()) + ->renderToString(); + LOG_TRACE << *str; }); return notFoundResp; }