From a09ff469eec1cbcd530f80733e1dc86b4d38346d Mon Sep 17 00:00:00 2001 From: whaffman Date: Thu, 30 Oct 2025 17:13:38 +0100 Subject: [PATCH] uri encode utils --- webserv/handler/URI.cpp | 7 +++---- webserv/handler/URI.hpp | 2 +- webserv/utils/utils.hpp | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 611d4bb..3e81076 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -16,7 +16,7 @@ URI::URI(const HttpRequest &request, const ServerConfig &serverConfig) : uriTrimmed_(utils::trim(request.getTarget(), "/")), config_(matchConfig(uriTrimmed_, serverConfig)) { Log::trace(LOCATION); - parseUri(request.getTarget()); + parseUri(); Log::debug("Parsed URI: " + uriTrimmed_, {{"ConfigType", config_->getType()}}); parseFullpath(); @@ -47,7 +47,7 @@ const AConfig *URI::matchConfig(const std::string &uri, const ServerConfig &serv return bestMatch; } -void URI::parseUri(const std::string &uri) +void URI::parseUri() { if (config_->getType() == "server") { @@ -57,9 +57,8 @@ void URI::parseUri(const std::string &uri) { auto const *locConfig = dynamic_cast(config_); std::string locTrimmed = utils::trim(locConfig->getPath(), "/"); - std::string uriTrimmed = utils::trim(uri, "/"); - std::string uriSub = uriTrimmed.substr(locTrimmed.length()); + std::string uriSub = uriTrimmed_.substr(locTrimmed.length()); fullPath_ = FileUtils::joinPath(locConfig->get("root").value_or(""), uriSub); } diff --git a/webserv/handler/URI.hpp b/webserv/handler/URI.hpp index c513ac1..22bdfc6 100644 --- a/webserv/handler/URI.hpp +++ b/webserv/handler/URI.hpp @@ -38,7 +38,7 @@ class URI [[nodiscard]] const std::string &getAuthority() const noexcept; private: - void parseUri(const std::string &uri); + void parseUri(); void parseFullpath(); std::string uriTrimmed_; diff --git a/webserv/utils/utils.hpp b/webserv/utils/utils.hpp index 688c84e..992ccb1 100644 --- a/webserv/utils/utils.hpp +++ b/webserv/utils/utils.hpp @@ -19,4 +19,6 @@ std::vector split(const std::string &str, char delimiter); std::string implode(const std::vector &elements, const std::string &delimiter); uint32_t stateToEpoll(const ASocket::IoState &event); +std::string uriEncode(const std::string &value); +std::string uriDecode(const std::string &value); } // namespace utils \ No newline at end of file