diff --git a/lib/inc/drogon/HttpAppFramework.h b/lib/inc/drogon/HttpAppFramework.h index 1ac2aa6a..04bacc44 100644 --- a/lib/inc/drogon/HttpAppFramework.h +++ b/lib/inc/drogon/HttpAppFramework.h @@ -108,8 +108,11 @@ class HttpAppFramework : public trantor::NonCopyable * @param resp is the object set to 404 response * After calling this method, the resp object is returned * by the HttpResponse::newNotFoundResponse() method. + * @param set404 if true, the status code of the resp will + * be set to 404 automatically */ - virtual HttpAppFramework &setCustom404Page(const HttpResponsePtr &resp) = 0; + virtual HttpAppFramework &setCustom404Page(const HttpResponsePtr &resp, + bool set404 = true) = 0; /// Get the plugin object registered in the framework /** diff --git a/lib/src/HttpAppFrameworkImpl.h b/lib/src/HttpAppFrameworkImpl.h index e1ba4430..d434a1b7 100644 --- a/lib/src/HttpAppFrameworkImpl.h +++ b/lib/src/HttpAppFrameworkImpl.h @@ -70,10 +70,13 @@ class HttpAppFrameworkImpl : public HttpAppFramework const std::vector &filtersAndMethods = std::vector{}) override; - virtual HttpAppFramework &setCustom404Page( - const HttpResponsePtr &resp) override + virtual HttpAppFramework &setCustom404Page(const HttpResponsePtr &resp, + bool set404) override { - resp->setStatusCode(k404NotFound); + if (set404) + { + resp->setStatusCode(k404NotFound); + } _custom404 = resp; return *this; }