mirror of https://github.com/kiwix/libkiwix.git
Enter HTTPErrorHtmlResponse
In addition to serving as a base class for `HTTP404HtmlResponse`, `HTTPErrorHtmlResponse` is going to be used for a couple of other error pages.
This commit is contained in:
parent
d8a60db739
commit
647118dd5e
|
@ -97,30 +97,45 @@ std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObjec
|
|||
return r;
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request)
|
||||
HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request,
|
||||
int httpStatusCode,
|
||||
const std::string& templateStr,
|
||||
const std::string& pageTitleMsg,
|
||||
const std::string& headingMsg)
|
||||
: ContentResponseBlueprint(&server,
|
||||
&request,
|
||||
MHD_HTTP_NOT_FOUND,
|
||||
"text/html",
|
||||
RESOURCE::templates::_404_html)
|
||||
httpStatusCode,
|
||||
"text/html; charset=utf-8",
|
||||
templateStr)
|
||||
{
|
||||
kainjow::mustache::list emptyList;
|
||||
this->m_data = kainjow::mustache::object{
|
||||
{"PAGE_TITLE", "Content not found"},
|
||||
{"PAGE_HEADING", "Not Found"},
|
||||
{"PAGE_TITLE", pageTitleMsg},
|
||||
{"PAGE_HEADING", headingMsg},
|
||||
{"details", emptyList}
|
||||
};
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(UrlNotFoundMsg /*unused*/)
|
||||
HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request)
|
||||
: HTTPErrorHtmlResponse(server,
|
||||
request,
|
||||
MHD_HTTP_NOT_FOUND,
|
||||
RESOURCE::templates::_404_html,
|
||||
"Content not found",
|
||||
"Not Found")
|
||||
{
|
||||
}
|
||||
|
||||
HTTPErrorHtmlResponse& HTTP404HtmlResponse::operator+(UrlNotFoundMsg /*unused*/)
|
||||
{
|
||||
const std::string requestUrl = m_request.get_full_url();
|
||||
kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)");
|
||||
return *this + msgTmpl.render({"url", requestUrl});
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const std::string& msg)
|
||||
HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const std::string& msg)
|
||||
{
|
||||
m_data["details"].push_back({"p", msg});
|
||||
return *this;
|
||||
|
|
|
@ -179,18 +179,30 @@ public: //data
|
|||
std::unique_ptr<TaskbarInfo> m_taskbarInfo;
|
||||
};
|
||||
|
||||
struct HTTPErrorHtmlResponse : ContentResponseBlueprint
|
||||
{
|
||||
HTTPErrorHtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request,
|
||||
int httpStatusCode,
|
||||
const std::string& templateStr,
|
||||
const std::string& pageTitleMsg,
|
||||
const std::string& headingMsg);
|
||||
|
||||
using ContentResponseBlueprint::operator+;
|
||||
HTTPErrorHtmlResponse& operator+(const std::string& msg);
|
||||
};
|
||||
|
||||
class UrlNotFoundMsg {};
|
||||
|
||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
||||
|
||||
struct HTTP404HtmlResponse : ContentResponseBlueprint
|
||||
struct HTTP404HtmlResponse : HTTPErrorHtmlResponse
|
||||
{
|
||||
HTTP404HtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request);
|
||||
|
||||
using ContentResponseBlueprint::operator+;
|
||||
HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
||||
HTTP404HtmlResponse& operator+(const std::string& errorDetails);
|
||||
using HTTPErrorHtmlResponse::operator+;
|
||||
HTTPErrorHtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
||||
};
|
||||
|
||||
class InvalidUrlMsg {};
|
||||
|
|
Loading…
Reference in New Issue