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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server,
|
||||||
const RequestContext& request)
|
const RequestContext& request,
|
||||||
|
int httpStatusCode,
|
||||||
|
const std::string& templateStr,
|
||||||
|
const std::string& pageTitleMsg,
|
||||||
|
const std::string& headingMsg)
|
||||||
: ContentResponseBlueprint(&server,
|
: ContentResponseBlueprint(&server,
|
||||||
&request,
|
&request,
|
||||||
MHD_HTTP_NOT_FOUND,
|
httpStatusCode,
|
||||||
"text/html",
|
"text/html; charset=utf-8",
|
||||||
RESOURCE::templates::_404_html)
|
templateStr)
|
||||||
{
|
{
|
||||||
kainjow::mustache::list emptyList;
|
kainjow::mustache::list emptyList;
|
||||||
this->m_data = kainjow::mustache::object{
|
this->m_data = kainjow::mustache::object{
|
||||||
{"PAGE_TITLE", "Content not found"},
|
{"PAGE_TITLE", pageTitleMsg},
|
||||||
{"PAGE_HEADING", "Not Found"},
|
{"PAGE_HEADING", headingMsg},
|
||||||
{"details", emptyList}
|
{"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();
|
const std::string requestUrl = m_request.get_full_url();
|
||||||
kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)");
|
kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)");
|
||||||
return *this + msgTmpl.render({"url", requestUrl});
|
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});
|
m_data["details"].push_back({"p", msg});
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -179,18 +179,30 @@ public: //data
|
||||||
std::unique_ptr<TaskbarInfo> m_taskbarInfo;
|
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 {};
|
class UrlNotFoundMsg {};
|
||||||
|
|
||||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
extern const UrlNotFoundMsg urlNotFoundMsg;
|
||||||
|
|
||||||
struct HTTP404HtmlResponse : ContentResponseBlueprint
|
struct HTTP404HtmlResponse : HTTPErrorHtmlResponse
|
||||||
{
|
{
|
||||||
HTTP404HtmlResponse(const InternalServer& server,
|
HTTP404HtmlResponse(const InternalServer& server,
|
||||||
const RequestContext& request);
|
const RequestContext& request);
|
||||||
|
|
||||||
using ContentResponseBlueprint::operator+;
|
using HTTPErrorHtmlResponse::operator+;
|
||||||
HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
HTTPErrorHtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
||||||
HTTP404HtmlResponse& operator+(const std::string& errorDetails);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidUrlMsg {};
|
class InvalidUrlMsg {};
|
||||||
|
|
Loading…
Reference in New Issue