42_tester shenanigans

This commit is contained in:
whaffman 2025-11-11 19:07:13 +01:00
parent bb55ffa75d
commit 02a8a407d4
4 changed files with 12 additions and 3 deletions

View File

@ -153,6 +153,7 @@ server {
}
server {
42_tester on;
listen 8083;
host 127.0.0.1;
server_name localhost;

View File

@ -20,7 +20,7 @@ class DirectiveFactory
std::string_view context;
};
constexpr static std::array<DirectiveInfo, 17> supportedDirectives = {{
constexpr static std::array<DirectiveInfo, 18> 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:

View File

@ -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<bool>("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();

View File

@ -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<bool>("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;
}