Add option to disable setting the 404 status code (#277)

This commit is contained in:
Daniel Mensinger 2019-10-11 15:54:01 +02:00 committed by An Tao
parent 8f5c757ce2
commit ddc41f7907
2 changed files with 10 additions and 4 deletions

View File

@ -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
/**

View File

@ -70,10 +70,13 @@ class HttpAppFrameworkImpl : public HttpAppFramework
const std::vector<internal::HttpConstraint> &filtersAndMethods =
std::vector<internal::HttpConstraint>{}) 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;
}