fix: enhance URI path handling

This commit is contained in:
whaffman 2025-10-29 12:11:20 +01:00
parent 5a2d801992
commit 3714004bad
3 changed files with 10 additions and 10 deletions

View File

@ -109,7 +109,7 @@ void Client::request()
}
catch (const RequestValidator::ValidationException &e)
{
Log::error("Exception during request handling: " + std::string(e.what()));
Log::error("Validation Exception during request handling: " + std::string(e.what()));
ErrorHandler::createErrorResponse(e.code(), *httpResponse_);
return;
}

View File

@ -218,26 +218,26 @@ std::string URI::getUriForPath(const std::string &path) const
{
// TOPD not good yet zo even naar kijken
std::string trimmedPath = utils::trim(path, "/");
std::string trimmedDir_;
std::string trimmedLocation;
const LocationConfig *locConfig = dynamic_cast<const LocationConfig *>(config_);
const auto *locConfig = dynamic_cast<const LocationConfig *>(config_);
if (locConfig != nullptr)
{
trimmedDir_ = utils::trim(locConfig->getPath(), "/");
trimmedLocation = utils::trim(locConfig->getPath(), "/");
}
std::string trimmedRoot_ = utils::trim(config_->get<std::string>("root").value_or(""), "/");
std::string trimmedRoot = utils::trim(config_->get<std::string>("root").value_or(""), "/");
if (trimmedPath.starts_with(trimmedRoot_))
if (trimmedPath.starts_with(trimmedRoot))
{
trimmedPath = trimmedDir_.substr(trimmedRoot_.length());
trimmedPath = trimmedPath.substr(trimmedRoot.length());
trimmedPath = utils::trim(trimmedPath, "/");
}
Log::debug("Generating URI for path", {{"path", path},{"trimmedDir", trimmedDir_}, {"trimmedPath", trimmedPath}, {"Authority", authority_}});
Log::debug("Generating URI for path", {{"path", path},{"trimmedDir", trimmedLocation}, {"trimmedPath", trimmedPath}, {"Authority", authority_}});
std::string result = "http://" + authority_;
result = FileUtils::joinPath(result, trimmedDir_);
result = FileUtils::joinPath(result, trimmedLocation);
return FileUtils::joinPath(result, trimmedPath);
}

View File

@ -39,7 +39,7 @@ std::string AutoIndex::generate(const std::string &dir, const URI &uri)
for (const auto &entry : entries)
{
std::string href = uri.getUriForPath(entry.path().filename().string());
std::string href = uri.getUriForPath(entry.path().string());
if (entry.is_directory())
{
href += "/";