mirror of https://github.com/kiwix/libkiwix.git
HTTP404HtmlResponse::operator+(UrlNotFoundMsg)
This commit is contained in:
parent
89785a259a
commit
1a5e2eda0f
|
@ -387,26 +387,6 @@ SuggestionsList_t getSuggestions(SuggestionSearcherCache& cache, const zim::Arch
|
|||
return suggestions;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class UrlNotFoundMsg {};
|
||||
|
||||
const UrlNotFoundMsg urlNotFoundMsg;
|
||||
|
||||
ContentResponseBlueprint&& operator+(ContentResponseBlueprint&& crb,
|
||||
UrlNotFoundMsg /*unused*/)
|
||||
{
|
||||
const std::string requestUrl = crb.m_request.get_full_url();
|
||||
kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{url}}" was not found on this server.)");
|
||||
const auto urlNotFoundMsgText = msgTmpl.render({"url", requestUrl});
|
||||
crb.m_data["details"].push_back({"p", urlNotFoundMsgText});
|
||||
return std::move(crb);
|
||||
}
|
||||
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request)
|
||||
{
|
||||
if (m_verbose.load()) {
|
||||
|
|
|
@ -109,6 +109,8 @@ std::unique_ptr<ContentResponse> Response::build_404(const InternalServer& serve
|
|||
return response;
|
||||
}
|
||||
|
||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
||||
|
||||
HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request)
|
||||
: ContentResponseBlueprint(&server,
|
||||
|
@ -121,6 +123,15 @@ HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
|||
this->m_data = kainjow::mustache::object{{"details", emptyList}};
|
||||
}
|
||||
|
||||
HTTP404HtmlResponse& 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.)");
|
||||
const auto urlNotFoundMsgText = msgTmpl.render({"url", requestUrl});
|
||||
m_data["details"].push_back({"p", urlNotFoundMsgText});
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
|
||||
{
|
||||
auto response = Response::build(server);
|
||||
|
|
|
@ -175,10 +175,16 @@ public: //data
|
|||
kainjow::mustache::data m_data;
|
||||
};
|
||||
|
||||
class UrlNotFoundMsg {};
|
||||
|
||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
||||
|
||||
struct HTTP404HtmlResponse : ContentResponseBlueprint
|
||||
{
|
||||
HTTP404HtmlResponse(const InternalServer& server,
|
||||
const RequestContext& request);
|
||||
|
||||
HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/);
|
||||
};
|
||||
|
||||
class ItemResponse : public Response {
|
||||
|
|
Loading…
Reference in New Issue