mirror of https://github.com/kiwix/libkiwix.git
Replaced UrlNotFoundMsg with UrlNotFoundResponse
This commit is contained in:
parent
3188b0afe6
commit
41f25083da
|
@ -593,8 +593,7 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (! request.is_valid_url()) {
|
if (! request.is_valid_url()) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( request.get_url() == "" ) {
|
if ( request.get_url() == "" ) {
|
||||||
|
@ -697,8 +696,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( startsWith(request.get_url(), "/suggest/") ) {
|
if ( startsWith(request.get_url(), "/suggest/") ) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bookName, bookId;
|
std::string bookName, bookId;
|
||||||
|
@ -817,12 +815,10 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
||||||
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
|
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
|
||||||
content = getNoJSDownloadPageHTML(bookId, userLang);
|
content = getNoJSDownloadPageHTML(bookId, userLang);
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
|
@ -873,8 +869,7 @@ std::unique_ptr<Response> InternalServer::handle_skin(const RequestContext& requ
|
||||||
response->set_kind(accessType);
|
response->set_kind(accessType);
|
||||||
return std::move(response);
|
return std::move(response);
|
||||||
} catch (const ResourceNotFound& e) {
|
} catch (const ResourceNotFound& e) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,8 +887,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
||||||
get_default_data(),
|
get_default_data(),
|
||||||
"application/opensearchdescription+xml");
|
"application/opensearchdescription+xml");
|
||||||
}
|
}
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1001,8 +995,7 @@ std::unique_ptr<Response> InternalServer::handle_random(const RequestContext& re
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( startsWith(request.get_url(), "/random/") ) {
|
if ( startsWith(request.get_url(), "/random/") ) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bookName;
|
std::string bookName;
|
||||||
|
@ -1037,8 +1030,7 @@ std::unique_ptr<Response> InternalServer::handle_captured_external(const Request
|
||||||
} catch (const std::out_of_range& e) {}
|
} catch (const std::out_of_range& e) {}
|
||||||
|
|
||||||
if (source.empty()) {
|
if (source.empty()) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = get_default_data();
|
auto data = get_default_data();
|
||||||
|
@ -1056,8 +1048,7 @@ std::unique_ptr<Response> InternalServer::handle_catch(const RequestContext& req
|
||||||
return handle_captured_external(request);
|
return handle_captured_external(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
|
@ -1141,8 +1132,7 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
|
||||||
|
|
||||||
if (archive == nullptr) {
|
if (archive == nullptr) {
|
||||||
const std::string searchURL = m_root + "/search?pattern=" + kiwix::urlEncode(pattern);
|
const std::string searchURL = m_root + "/search?pattern=" + kiwix::urlEncode(pattern);
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request)
|
||||||
+ urlNotFoundMsg
|
|
||||||
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
|
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,8 +1179,7 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
|
||||||
printf("Failed to find %s\n", urlStr.c_str());
|
printf("Failed to find %s\n", urlStr.c_str());
|
||||||
|
|
||||||
std::string searchURL = m_root + "/search?content=" + bookName + "&pattern=" + kiwix::urlEncode(pattern);
|
std::string searchURL = m_root + "/search?content=" + bookName + "&pattern=" + kiwix::urlEncode(pattern);
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request)
|
||||||
+ urlNotFoundMsg
|
|
||||||
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
|
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1208,13 +1197,11 @@ std::unique_ptr<Response> InternalServer::handle_raw(const RequestContext& reque
|
||||||
bookName = request.get_url_part(1);
|
bookName = request.get_url_part(1);
|
||||||
kind = request.get_url_part(2);
|
kind = request.get_url_part(2);
|
||||||
} catch (const std::out_of_range& e) {
|
} catch (const std::out_of_range& e) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind != "meta" && kind!= "content") {
|
if (kind != "meta" && kind!= "content") {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request)
|
||||||
+ urlNotFoundMsg
|
|
||||||
+ invalidRawAccessMsg(kind);
|
+ invalidRawAccessMsg(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1225,8 +1212,7 @@ std::unique_ptr<Response> InternalServer::handle_raw(const RequestContext& reque
|
||||||
} catch (const std::out_of_range& e) {}
|
} catch (const std::out_of_range& e) {}
|
||||||
|
|
||||||
if (archive == nullptr) {
|
if (archive == nullptr) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request)
|
||||||
+ urlNotFoundMsg
|
|
||||||
+ noSuchBookErrorMsg(bookName);
|
+ noSuchBookErrorMsg(bookName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,8 +1246,7 @@ std::unique_ptr<Response> InternalServer::handle_raw(const RequestContext& reque
|
||||||
if (m_verbose.load()) {
|
if (m_verbose.load()) {
|
||||||
printf("Failed to find %s\n", itemPath.c_str());
|
printf("Failed to find %s\n", itemPath.c_str());
|
||||||
}
|
}
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request)
|
||||||
+ urlNotFoundMsg
|
|
||||||
+ rawEntryNotFoundMsg(kind, itemPath);
|
+ rawEntryNotFoundMsg(kind, itemPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog(const RequestContext& r
|
||||||
host = request.get_header("Host");
|
host = request.get_header("Host");
|
||||||
url = request.get_url_part(1);
|
url = request.get_url_part(1);
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == "v2") {
|
if (url == "v2") {
|
||||||
|
@ -72,8 +71,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog(const RequestContext& r
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != "searchdescription.xml" && url != "root.xml" && url != "search") {
|
if (url != "searchdescription.xml" && url != "root.xml" && url != "search") {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == "searchdescription.xml") {
|
if (url == "searchdescription.xml") {
|
||||||
|
@ -111,8 +109,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2(const RequestContext
|
||||||
try {
|
try {
|
||||||
url = request.get_url_part(2);
|
url = request.get_url_part(2);
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == "root.xml") {
|
if (url == "root.xml") {
|
||||||
|
@ -138,8 +135,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2(const RequestContext
|
||||||
} else if (url == "illustration") {
|
} else if (url == "illustration") {
|
||||||
return handle_catalog_v2_illustration(request);
|
return handle_catalog_v2_illustration(request);
|
||||||
} else {
|
} else {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,8 +177,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_complete_entry(const
|
||||||
try {
|
try {
|
||||||
mp_library->getBookById(entryId);
|
mp_library->getBookById(entryId);
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OPDSDumper opdsDumper(mp_library.get(), mp_nameMapper.get());
|
OPDSDumper opdsDumper(mp_library.get(), mp_nameMapper.get());
|
||||||
|
@ -233,8 +228,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_illustration(const R
|
||||||
illustration->mimeType
|
illustration->mimeType
|
||||||
);
|
);
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
return HTTP404Response(*this, request)
|
return UrlNotFoundResponse(*this, request);
|
||||||
+ urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,6 @@ std::unique_ptr<Response> Response::build_304(const InternalServer& server, cons
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UrlNotFoundMsg urlNotFoundMsg;
|
|
||||||
const InvalidUrlMsg invalidUrlMsg;
|
const InvalidUrlMsg invalidUrlMsg;
|
||||||
|
|
||||||
std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const
|
std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const
|
||||||
|
@ -198,10 +197,12 @@ HTTP404Response::HTTP404Response(const InternalServer& server,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPErrorResponse& HTTP404Response::operator+(UrlNotFoundMsg /*unused*/)
|
UrlNotFoundResponse::UrlNotFoundResponse(const InternalServer& server,
|
||||||
|
const RequestContext& request)
|
||||||
|
: HTTP404Response(server, request)
|
||||||
{
|
{
|
||||||
const std::string requestUrl = urlDecode(m_request.get_full_url(), false);
|
const std::string requestUrl = urlDecode(m_request.get_full_url(), false);
|
||||||
return *this + ParameterizedMessage("url-not-found", {{"url", requestUrl}});
|
*this += ParameterizedMessage("url-not-found", {{"url", requestUrl}});
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPErrorResponse& HTTPErrorResponse::operator+(const std::string& msg)
|
HTTPErrorResponse& HTTPErrorResponse::operator+(const std::string& msg)
|
||||||
|
|
|
@ -174,17 +174,18 @@ struct HTTPErrorResponse : ContentResponseBlueprint
|
||||||
HTTPErrorResponse& operator+=(const ParameterizedMessage& errorDetails);
|
HTTPErrorResponse& operator+=(const ParameterizedMessage& errorDetails);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UrlNotFoundMsg {};
|
|
||||||
|
|
||||||
extern const UrlNotFoundMsg urlNotFoundMsg;
|
|
||||||
|
|
||||||
struct HTTP404Response : HTTPErrorResponse
|
struct HTTP404Response : HTTPErrorResponse
|
||||||
{
|
{
|
||||||
HTTP404Response(const InternalServer& server,
|
HTTP404Response(const InternalServer& server,
|
||||||
const RequestContext& request);
|
const RequestContext& request);
|
||||||
|
|
||||||
using HTTPErrorResponse::operator+;
|
using HTTPErrorResponse::operator+;
|
||||||
HTTPErrorResponse& operator+(UrlNotFoundMsg /*unused*/);
|
};
|
||||||
|
|
||||||
|
struct UrlNotFoundResponse : HTTP404Response
|
||||||
|
{
|
||||||
|
UrlNotFoundResponse(const InternalServer& server,
|
||||||
|
const RequestContext& request);
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidUrlMsg {};
|
class InvalidUrlMsg {};
|
||||||
|
|
Loading…
Reference in New Issue