mirror of https://github.com/kiwix/libkiwix.git
Introduce operator+= to simplify response creation.
This commit is contained in:
parent
f42f6a60df
commit
4695f47dd2
|
@ -633,12 +633,13 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
||||||
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
|
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
|
||||||
// (in case of zim file not containing a index)
|
// (in case of zim file not containing a index)
|
||||||
const auto cssUrl = renderUrl(m_root, RESOURCE::templates::url_of_search_results_css);
|
const auto cssUrl = renderUrl(m_root, RESOURCE::templates::url_of_search_results_css);
|
||||||
return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND,
|
HTTPErrorHtmlResponse response(*this, request, MHD_HTTP_NOT_FOUND,
|
||||||
"fulltext-search-unavailable",
|
"fulltext-search-unavailable",
|
||||||
"404-page-heading",
|
"404-page-heading",
|
||||||
cssUrl)
|
cssUrl);
|
||||||
+ nonParameterizedMessage("no-search-results")
|
response += nonParameterizedMessage("no-search-results");
|
||||||
+ TaskbarInfo(searchInfo.bookName, archive.get());
|
response += TaskbarInfo(searchInfo.bookName, archive.get());
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,12 @@ HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const ParameterizedMessa
|
||||||
return *this + details.getText(m_request.get_user_language());
|
return *this + details.getText(m_request.get_user_language());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+=(const ParameterizedMessage& details)
|
||||||
|
{
|
||||||
|
// operator+() is already a state-modifying operator (akin to operator+=)
|
||||||
|
return *this + details;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server,
|
HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server,
|
||||||
const RequestContext& request)
|
const RequestContext& request)
|
||||||
|
@ -246,6 +252,13 @@ ContentResponseBlueprint& ContentResponseBlueprint::operator+(const TaskbarInfo&
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentResponseBlueprint& ContentResponseBlueprint::operator+=(const TaskbarInfo& taskbarInfo)
|
||||||
|
{
|
||||||
|
// operator+() is already a state-modifying operator (akin to operator+=)
|
||||||
|
return *this + taskbarInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
|
std::unique_ptr<Response> Response::build_416(const InternalServer& server, size_t resourceLength)
|
||||||
{
|
{
|
||||||
auto response = Response::build(server);
|
auto response = Response::build(server);
|
||||||
|
|
|
@ -165,6 +165,7 @@ public: // functions
|
||||||
|
|
||||||
|
|
||||||
ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo);
|
ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo);
|
||||||
|
ContentResponseBlueprint& operator+=(const TaskbarInfo& taskbarInfo);
|
||||||
|
|
||||||
protected: // functions
|
protected: // functions
|
||||||
std::string getMessage(const std::string& msgId) const;
|
std::string getMessage(const std::string& msgId) const;
|
||||||
|
@ -190,8 +191,10 @@ struct HTTPErrorHtmlResponse : ContentResponseBlueprint
|
||||||
const std::string& cssUrl = "");
|
const std::string& cssUrl = "");
|
||||||
|
|
||||||
using ContentResponseBlueprint::operator+;
|
using ContentResponseBlueprint::operator+;
|
||||||
|
using ContentResponseBlueprint::operator+=;
|
||||||
HTTPErrorHtmlResponse& operator+(const std::string& msg);
|
HTTPErrorHtmlResponse& operator+(const std::string& msg);
|
||||||
HTTPErrorHtmlResponse& operator+(const ParameterizedMessage& errorDetails);
|
HTTPErrorHtmlResponse& operator+(const ParameterizedMessage& errorDetails);
|
||||||
|
HTTPErrorHtmlResponse& operator+=(const ParameterizedMessage& errorDetails);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UrlNotFoundMsg {};
|
class UrlNotFoundMsg {};
|
||||||
|
|
Loading…
Reference in New Issue