From 02a8a407d44b59b786e258288fbd2fbbcd9698f5 Mon Sep 17 00:00:00 2001 From: whaffman Date: Tue, 11 Nov 2025 19:07:13 +0100 Subject: [PATCH] 42_tester shenanigans --- config/default.conf | 1 + webserv/config/directive/DirectiveFactory.hpp | 3 ++- webserv/handler/CgiEnvironment.cpp | 6 +++++- webserv/handler/URI.cpp | 5 ++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/default.conf b/config/default.conf index e5d7248..fc50107 100644 --- a/config/default.conf +++ b/config/default.conf @@ -153,6 +153,7 @@ server { } server { + 42_tester on; listen 8083; host 127.0.0.1; server_name localhost; diff --git a/webserv/config/directive/DirectiveFactory.hpp b/webserv/config/directive/DirectiveFactory.hpp index 96d13ec..2e84e1c 100644 --- a/webserv/config/directive/DirectiveFactory.hpp +++ b/webserv/config/directive/DirectiveFactory.hpp @@ -20,7 +20,7 @@ class DirectiveFactory std::string_view context; }; - constexpr static std::array supportedDirectives = {{ + constexpr static std::array supportedDirectives = {{ {.name = "listen", .type = "IntDirective", .context = "S"}, {.name = "host", .type = "StringDirective", .context = "S"}, {.name = "server_name", .type = "VectorDirective", .context = "S"}, @@ -38,6 +38,7 @@ class DirectiveFactory {.name = "redirect", .type = "IntStringDirective", .context = "l"}, {.name = "timeout", .type = "IntDirective", .context = "gsl"}, {.name = "default", .type = "BoolDirective", .context = "S"}, + {.name = "42_tester", .type = "BoolDirective", .context = "s"} }}; private: diff --git a/webserv/handler/CgiEnvironment.cpp b/webserv/handler/CgiEnvironment.cpp index 84296cd..3985628 100644 --- a/webserv/handler/CgiEnvironment.cpp +++ b/webserv/handler/CgiEnvironment.cpp @@ -22,7 +22,11 @@ CgiEnvironment::CgiEnvironment(const URI &uri, const HttpRequest &request) env_["SCRIPT_FILENAME"] = uri.getFullPath(); // Full filesystem path to the script (required by PHP) env_["QUERY_STRING"] = uri.getQuery(); env_["REQUEST_URI"] = request.getTarget(); - env_["PATH_INFO"] = request.getTarget(); // TODO This is only correct for the tester; + env_["PATH_INFO"] = uri.getPathInfo(); + if (uri.getConfig()->get("42_tester").value_or(false)) + { + env_["PATH_INFO"] = request.getTarget(); // TODO This is only correct for the tester; + } // Only set CONTENT_TYPE and CONTENT_LENGTH if they have values auto contentType = request.getHeaders().getContentType(); diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 3465f71..da9f1f7 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -134,7 +134,10 @@ void URI::parseFullpath() else // not file or dir, and no baseName yet { valid_ = false; - baseName_ = segment; // TODO: is this correct? works for tester but seems odd + if (config_->get("42_tester").value_or(false)) + { + baseName_ = segment; // TODO: is this correct? works for tester but seems odd + } Log::warning("Invalid path segment encountered: " + currentPath); return; }