mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-26 13:50:33 -04:00
Merge pull request #199 from kiwix/kiwix_server_404
return 404 for missing resources
This commit is contained in:
commit
4cd9d78d21
@ -443,7 +443,7 @@ static struct MHD_Response* handle_suggest(RequestContext* request)
|
|||||||
humanReadableBookId = request->get_argument("content");
|
humanReadableBookId = request->get_argument("content");
|
||||||
term = request->get_argument("term");
|
term = request->get_argument("term");
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return build_homepage(request);
|
return build_404(request, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVerbose.load()) {
|
if (isVerbose.load()) {
|
||||||
@ -628,12 +628,12 @@ static struct MHD_Response* handle_random(RequestContext* request)
|
|||||||
try {
|
try {
|
||||||
humanReadableBookId = request->get_argument("content");
|
humanReadableBookId = request->get_argument("content");
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return build_homepage(request);
|
return build_404(request, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reader = get_from_humanReadableBookId(humanReadableBookId).first;
|
auto reader = get_from_humanReadableBookId(humanReadableBookId).first;
|
||||||
if (reader == nullptr) {
|
if (reader == nullptr) {
|
||||||
return build_homepage(request);
|
return build_404(request, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -728,7 +728,11 @@ static struct MHD_Response* handle_content(RequestContext* request)
|
|||||||
|
|
||||||
auto reader = get_from_humanReadableBookId(humanReadableBookId).first;
|
auto reader = get_from_humanReadableBookId(humanReadableBookId).first;
|
||||||
if (reader == nullptr) {
|
if (reader == nullptr) {
|
||||||
return build_homepage(request);
|
if (humanReadableBookId.size() == 0){
|
||||||
|
return build_homepage(request);
|
||||||
|
} else {
|
||||||
|
return build_404(request, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto urlStr = request->get_url().substr(humanReadableBookId.size()+1);
|
auto urlStr = request->get_url().substr(humanReadableBookId.size()+1);
|
||||||
@ -842,7 +846,7 @@ static int accessHandlerCallback(void* cls,
|
|||||||
request.httpResponseCode = request.has_range() ? MHD_HTTP_PARTIAL_CONTENT : MHD_HTTP_OK;
|
request.httpResponseCode = request.has_range() ? MHD_HTTP_PARTIAL_CONTENT : MHD_HTTP_OK;
|
||||||
|
|
||||||
if (! request.is_valid_url()) {
|
if (! request.is_valid_url()) {
|
||||||
response = build_homepage(&request);
|
response = build_404(&request, "");
|
||||||
} else {
|
} else {
|
||||||
if (startswith(request.get_url(), "/skin/")) {
|
if (startswith(request.get_url(), "/skin/")) {
|
||||||
response = handle_skin(&request);
|
response = handle_skin(&request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user