Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Lukas Senionis <[email protected]>
  • Loading branch information
ReenigneArcher and FrogTheFrog committed Jan 10, 2025
1 parent b2c70ad commit c52a641
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace confighttp {

/**
* @brief Send a response.
* This is used when an endpoint returns early, such as when hitting bad_request.
* @param response The HTTP response object.
* @param output_tree The JSON tree to send.
*/
Expand Down Expand Up @@ -437,16 +436,16 @@ namespace confighttp {
// remove the leading period from the extension
auto mimeType = mime_types.find(relPath.extension().string().substr(1));
// check if the extension is in the map at the x position
if (mimeType != mime_types.end()) {
// if it is, set the content type to the mime type
SimpleWeb::CaseInsensitiveMultimap headers;
headers.emplace("Content-Type", mimeType->second);
std::ifstream in(filePath.string(), std::ios::binary);
response->write(SimpleWeb::StatusCode::success_ok, in, headers);
if (mimeType == mime_types.end()) {
bad_request(response, request);
return;
}

// do not return any file if the type is not in the map
bad_request(response, request);
// if it is, set the content type to the mime type
SimpleWeb::CaseInsensitiveMultimap headers;
headers.emplace("Content-Type", mimeType->second);
std::ifstream in(filePath.string(), std::ios::binary);
response->write(SimpleWeb::StatusCode::success_ok, in, headers);
}

/**
Expand Down Expand Up @@ -621,7 +620,7 @@ namespace confighttp {
auto &apps_node = fileTree.get_child("apps"s);
index = stoi(request->path_match[1]);

if (std::clamp(index, 0, static_cast<int>(apps_node.size()) - 1) != index) {
if (index < 0 && index >= static_cast<int>(apps_node.size())) {
bad_request(response, request, "index out of range, max index is "s + std::to_string(apps_node.size() - 1));
return;
}
Expand Down

0 comments on commit c52a641

Please sign in to comment.