From 3714004bad50e3d9c83820d75f2b2edc6ad8ad32 Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 29 Oct 2025 12:11:20 +0100 Subject: [PATCH] fix: enhance URI path handling --- webserv/client/Client.cpp | 2 +- webserv/handler/URI.cpp | 16 ++++++++-------- webserv/utils/AutoIndex.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/webserv/client/Client.cpp b/webserv/client/Client.cpp index 2742c95..2056608 100644 --- a/webserv/client/Client.cpp +++ b/webserv/client/Client.cpp @@ -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; } diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 10915ab..08fbc6a 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -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(config_); + const auto *locConfig = dynamic_cast(config_); if (locConfig != nullptr) { - trimmedDir_ = utils::trim(locConfig->getPath(), "/"); + trimmedLocation = utils::trim(locConfig->getPath(), "/"); } - std::string trimmedRoot_ = utils::trim(config_->get("root").value_or(""), "/"); + std::string trimmedRoot = utils::trim(config_->get("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); } diff --git a/webserv/utils/AutoIndex.cpp b/webserv/utils/AutoIndex.cpp index 3f21ebe..c6180fd 100644 --- a/webserv/utils/AutoIndex.cpp +++ b/webserv/utils/AutoIndex.cpp @@ -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 += "/";