fix: add utils namespace to functions

This commit is contained in:
Quinten Mennen 2025-09-24 13:01:27 +02:00
parent f611ace342
commit 36961fc468
4 changed files with 18 additions and 10 deletions

View File

@ -39,9 +39,9 @@ void removeEmptyLines(std::string &str)
while (std::getline(stream, line))
{
if (!trim(line).empty())
if (!utils::trim(line).empty())
{
result += trimSemi(trim(line)) + '\n';
result += utils::trimSemi(utils::trim(line)) + '\n';
}
}
str = result;
@ -97,7 +97,7 @@ void ConfigManager::parseConfigFile(const std::string &filePath)
}
// Add global declarations before this server block
globalDeclarations += content.substr(pos, serverPos - pos);
size_t closeBrace = findCorrespondingClosingBrace(content, bracePos);
size_t closeBrace = utils::findCorrespondingClosingBrace(content, bracePos);
if (closeBrace == std::string::npos)
{
throw std::runtime_error("Malformed block in config file.");

View File

@ -22,7 +22,7 @@ void LocationConfig::parseDirectives(const std::string &declarations)
while (std::getline(stream, line))
{
std::string directive;
std::istringstream lineStream{trim(line)};
std::istringstream lineStream{utils::trim(line)};
lineStream >> directive;
if (!directive.empty())
{

View File

@ -36,10 +36,10 @@ void ServerConfig::parseServerBlock(const std::string &block)
serverDeclarations += block.substr(pos);
break;
}
std::string locationPath = trim(block.substr(locationPos, bracePos - (locationPos)));
std::string locationPath = utils::trim(block.substr(locationPos, bracePos - (locationPos)));
// Add global declarations before this server block
serverDeclarations += block.substr(pos, locationPos - pos);
size_t closeBrace = findCorrespondingClosingBrace(block, bracePos);
size_t closeBrace = utils::findCorrespondingClosingBrace(block, bracePos);
if (closeBrace == std::string::npos)
{
throw std::runtime_error("Malformed block in config file.");
@ -111,7 +111,7 @@ void ServerConfig::parseDirectives(const std::string &declarations)
}
else if (directive == "error_page")
{
int statusCode = std::stoi(value);
int statusCode = std::stoi("-1");
std::string errorPagePath;
lineStream >> errorPagePath;
Log::debug("Set error_page for status " + std::to_string(statusCode) + " to " + errorPagePath);

View File

@ -1,3 +1,5 @@
#include "webserv/log/Log.hpp"
#include <webserv/config/utils.hpp> // for trim
#include <webserv/http/HttpConstants.hpp> // for CRLF
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
@ -14,12 +16,18 @@ std::optional<size_t> HttpHeaders::getContentLength() const
{
return std::nullopt;
}
if (value.find_first_not_of("0123456789") != std::string::npos)
{
Log::warning("Non-numeric Content-Length header value: " + value);
return std::nullopt;
}
try
{
return std::stoul(value);
return utils::stoul(value);
}
catch (...)
{
Log::warning("Invalid Content-Length header value: " + value);
return std::nullopt;
}
}
@ -90,8 +98,8 @@ void HttpHeaders::parse(const std::string &rawHeaders)
{
std::string name = line.substr(0, col);
std::string value = line.substr(col + 1);
name = trim(name);
value = trim(value);
name = utils::trim(name);
value = utils::trim(value);
this->add(name, value);
}
start = end + Http::Protocol::CRLF.size();