fix: add utils namespace to functions
This commit is contained in:
parent
f611ace342
commit
36961fc468
@ -39,9 +39,9 @@ void removeEmptyLines(std::string &str)
|
|||||||
|
|
||||||
while (std::getline(stream, line))
|
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;
|
str = result;
|
||||||
@ -97,7 +97,7 @@ void ConfigManager::parseConfigFile(const std::string &filePath)
|
|||||||
}
|
}
|
||||||
// Add global declarations before this server block
|
// Add global declarations before this server block
|
||||||
globalDeclarations += content.substr(pos, serverPos - pos);
|
globalDeclarations += content.substr(pos, serverPos - pos);
|
||||||
size_t closeBrace = findCorrespondingClosingBrace(content, bracePos);
|
size_t closeBrace = utils::findCorrespondingClosingBrace(content, bracePos);
|
||||||
if (closeBrace == std::string::npos)
|
if (closeBrace == std::string::npos)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Malformed block in config file.");
|
throw std::runtime_error("Malformed block in config file.");
|
||||||
|
|||||||
@ -22,7 +22,7 @@ void LocationConfig::parseDirectives(const std::string &declarations)
|
|||||||
while (std::getline(stream, line))
|
while (std::getline(stream, line))
|
||||||
{
|
{
|
||||||
std::string directive;
|
std::string directive;
|
||||||
std::istringstream lineStream{trim(line)};
|
std::istringstream lineStream{utils::trim(line)};
|
||||||
lineStream >> directive;
|
lineStream >> directive;
|
||||||
if (!directive.empty())
|
if (!directive.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -36,10 +36,10 @@ void ServerConfig::parseServerBlock(const std::string &block)
|
|||||||
serverDeclarations += block.substr(pos);
|
serverDeclarations += block.substr(pos);
|
||||||
break;
|
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
|
// Add global declarations before this server block
|
||||||
serverDeclarations += block.substr(pos, locationPos - pos);
|
serverDeclarations += block.substr(pos, locationPos - pos);
|
||||||
size_t closeBrace = findCorrespondingClosingBrace(block, bracePos);
|
size_t closeBrace = utils::findCorrespondingClosingBrace(block, bracePos);
|
||||||
if (closeBrace == std::string::npos)
|
if (closeBrace == std::string::npos)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Malformed block in config file.");
|
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")
|
else if (directive == "error_page")
|
||||||
{
|
{
|
||||||
int statusCode = std::stoi(value);
|
int statusCode = std::stoi("-1");
|
||||||
std::string errorPagePath;
|
std::string errorPagePath;
|
||||||
lineStream >> errorPagePath;
|
lineStream >> errorPagePath;
|
||||||
Log::debug("Set error_page for status " + std::to_string(statusCode) + " to " + errorPagePath);
|
Log::debug("Set error_page for status " + std::to_string(statusCode) + " to " + errorPagePath);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include "webserv/log/Log.hpp"
|
||||||
|
|
||||||
#include <webserv/config/utils.hpp> // for trim
|
#include <webserv/config/utils.hpp> // for trim
|
||||||
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
||||||
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
@ -14,12 +16,18 @@ std::optional<size_t> HttpHeaders::getContentLength() const
|
|||||||
{
|
{
|
||||||
return std::nullopt;
|
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
|
try
|
||||||
{
|
{
|
||||||
return std::stoul(value);
|
return utils::stoul(value);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
Log::warning("Invalid Content-Length header value: " + value);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,8 +98,8 @@ void HttpHeaders::parse(const std::string &rawHeaders)
|
|||||||
{
|
{
|
||||||
std::string name = line.substr(0, col);
|
std::string name = line.substr(0, col);
|
||||||
std::string value = line.substr(col + 1);
|
std::string value = line.substr(col + 1);
|
||||||
name = trim(name);
|
name = utils::trim(name);
|
||||||
value = trim(value);
|
value = utils::trim(value);
|
||||||
this->add(name, value);
|
this->add(name, value);
|
||||||
}
|
}
|
||||||
start = end + Http::Protocol::CRLF.size();
|
start = end + Http::Protocol::CRLF.size();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user