moved sites to htdocs and ran format script

This commit is contained in:
whaffman 2025-10-09 22:57:31 +02:00
parent fc1340ac7f
commit 4614a2d382
66 changed files with 248 additions and 219 deletions

View File

@ -1,17 +1,17 @@
autoindex on autoindex on
error_page 400 ./error_pages/400.html error_page 400 ./htdocs/error_pages/400.html
error_page 500 ./error_pages/500.html error_page 500 ./htdocs/error_pages/500.html
server { server {
listen 8080; listen 8080;
host 0.0.0.0; host 0.0.0.0;
server_name localhost; server_name localhost;
root ./www/; root ./htdocs/site-1/;
index index.html index.htm; index index.html index.htm;
error_page 400 /400.html; error_page 400 ./htdocs/error_pages/400.html;
error_page 404 ./error_pages/404.html; error_page 404 ./htdocs/error_pages/404.html;
error_page 403 /403.html; error_page 403 /403.html;
error_page 404 /404.html; error_page 404 /404.html;
error_page 405 /405.html; error_page 405 /405.html;
@ -24,7 +24,7 @@ server {
location / { location / {
autoindex off; autoindex off;
root ./static_site/; root ./htdocs/site-1/;
index index2.html index.html; index index2.html index.html;
allowed_methods GET POST DELETE; allowed_methods GET POST DELETE;
} }
@ -36,7 +36,7 @@ server {
# } # }
location /images { location /images {
root ./static_site/img; root ./htdocs/site-1/img;
autoindex off; autoindex off;
index index.jpg; index index.jpg;
allowed_methods GET; allowed_methods GET;
@ -51,7 +51,7 @@ server {
host 127.0.0.1; host 127.0.0.1;
server_name localhost; server_name localhost;
root ./www; root ./htdocs/site-2/;
index index.html index2.htm; index index.html index2.htm;
error_page 400; error_page 400;
@ -67,7 +67,7 @@ server {
location / { location / {
autoindex off; autoindex off;
root www; root ./htdocs/site-2/;
index index.html; index index.html;
allowed_methods GET POST DELETE; allowed_methods GET POST DELETE;
} }

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 151 KiB

View File

@ -78,7 +78,7 @@ TEST_F(LogTest, LogLevelToColoredString)
TEST_F(LogTest, StdoutChannelConstruction) TEST_F(LogTest, StdoutChannelConstruction)
{ {
StdoutChannel channel(); StdoutChannel channel;
// If we reach here without exception, construction was successful // If we reach here without exception, construction was successful
SUCCEED(); SUCCEED();
} }

View File

@ -15,8 +15,8 @@
#include <sys/types.h> // for ssize_t #include <sys/types.h> // for ssize_t
Client::Client(std::unique_ptr<Socket> socket, Server &server) Client::Client(std::unique_ptr<Socket> socket, Server &server)
: httpRequest_(std::make_unique<HttpRequest>(this)), httpResponse_(std::make_unique<HttpResponse>()), client_socket_(std::move(socket)), : httpRequest_(std::make_unique<HttpRequest>(this)), httpResponse_(std::make_unique<HttpResponse>()),
server_(std::ref(server)) client_socket_(std::move(socket)), server_(std::ref(server))
{ {
Log::trace(LOCATION); Log::trace(LOCATION);
Log::info("New client connected, fd: " + std::to_string(client_socket_->getFd())); Log::info("New client connected, fd: " + std::to_string(client_socket_->getFd()));
@ -45,8 +45,8 @@ void Client::request()
{ {
Log::trace(LOCATION); Log::trace(LOCATION);
char buffer[bufferSize_] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays) char buffer[bufferSize_] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays)
ssize_t bytesRead = ssize_t bytesRead = client_socket_->recv(
client_socket_->recv(buffer, sizeof(buffer) - 1); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) buffer, sizeof(buffer) - 1); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
if (bytesRead < 0) if (bytesRead < 0)
{ {
Log::error("Read error"); Log::error("Read error");
@ -62,8 +62,8 @@ void Client::request()
buffer[bytesRead] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) buffer[bytesRead] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
httpRequest_->receiveData(static_cast<const char *>(buffer), static_cast<size_t>(bytesRead)); httpRequest_->receiveData(static_cast<const char *>(buffer), static_cast<size_t>(bytesRead));
if (httpRequest_->getState() == HttpRequest::State::Complete || if (httpRequest_->getState() == HttpRequest::State::Complete
httpRequest_->getState() == HttpRequest::State::ParseError) || httpRequest_->getState() == HttpRequest::State::ParseError)
{ {
Log::info("Received complete request", Log::info("Received complete request",
{ {

View File

@ -1,4 +1,5 @@
#include <webserv/config/AConfig.hpp> // for AConfig #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/directive/ADirective.hpp> // for ADirective #include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory #include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue #include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
@ -52,7 +53,7 @@ bool AConfig::has(const std::string &name) const
{ {
return true; return true;
} }
if (parent_ != nullptr) if (parent_ != nullptr)
{ {
return parent_->has(name); return parent_->has(name);

View File

@ -18,8 +18,8 @@ ServerConfig::ServerConfig(const std::string &block, const AConfig *parent) : AC
std::string ServerConfig::getName() const std::string ServerConfig::getName() const
{ {
return "server: " + get<std::string>("server_name").value_or("unnamed") + " (port " + return "server: " + get<std::string>("server_name").value_or("unnamed") + " (port "
std::to_string(get<int>("listen").value_or(-1)) + ")"; + std::to_string(get<int>("listen").value_or(-1)) + ")";
} }
std::string ServerConfig::getType() const std::string ServerConfig::getType() const
@ -45,8 +45,8 @@ void ServerConfig::parseBlock(const std::string &block)
directives += block.substr(pos); directives += block.substr(pos);
break; break;
} }
std::string locationPath = std::string locationPath
utils::trim(block.substr(locationPos + 9, bracePos - (locationPos + 9))); // TODO magic numbers = utils::trim(block.substr(locationPos + 9, bracePos - (locationPos + 9))); // TODO magic numbers
// Add global declarations before this server block // Add global declarations before this server block
directives += block.substr(pos, locationPos - pos); directives += block.substr(pos, locationPos - pos);
size_t closeBrace = utils::findCorrespondingClosingBrace(block, bracePos); size_t closeBrace = utils::findCorrespondingClosingBrace(block, bracePos);

View File

@ -20,7 +20,6 @@ class DirectiveFactory
std::string_view context; std::string_view context;
}; };
constexpr static std::array<DirectiveInfo, 15> supportedDirectives = {{ constexpr static std::array<DirectiveInfo, 15> supportedDirectives = {{
{.name = "listen", .type = "IntDirective", .context = "S"}, {.name = "listen", .type = "IntDirective", .context = "S"},
{.name = "host", .type = "StringDirective", .context = "S"}, {.name = "host", .type = "StringDirective", .context = "S"},
@ -38,13 +37,10 @@ class DirectiveFactory
{.name = "upload_store", .type = "StringDirective", .context = "gsl"}, {.name = "upload_store", .type = "StringDirective", .context = "gsl"},
{.name = "redirect", .type = "VectorDirective", .context = "l"}, {.name = "redirect", .type = "VectorDirective", .context = "l"},
}}; }};
private: private:
using CreatorFunc = std::function<std::unique_ptr<ADirective>(const std::string &, const std::string &arg)>; using CreatorFunc = std::function<std::unique_ptr<ADirective>(const std::string &, const std::string &arg)>;
static const std::unordered_map<std::string_view, CreatorFunc> &getFactories(); static const std::unordered_map<std::string_view, CreatorFunc> &getFactories();
static std::unique_ptr<ADirective> create(std::string_view type, const std::string &name, const std::string &arg); static std::unique_ptr<ADirective> create(std::string_view type, const std::string &name, const std::string &arg);
}; };

View File

@ -1,18 +1,24 @@
#include <webserv/config/validation/ConfigValidator.hpp> #include <webserv/config/validation/ConfigValidator.hpp>
#include <webserv/config/validation/directive_rules/CgiExtValidationRule.hpp> #include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine
#include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine #include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule #include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp> // for AllowedValuesRule
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp> // for AllowedValuesRule #include <webserv/config/validation/directive_rules/CgiExtValidationRule.hpp> // for CgiExtValidationRule
#include <webserv/config/validation/directive_rules/FolderExistsRule.hpp> #include <webserv/config/validation/directive_rules/FolderExistsRule.hpp> // for FolderExistsRule
#include <webserv/config/validation/directive_rules/HostValidationRule.hpp> #include <webserv/config/validation/directive_rules/HostValidationRule.hpp> // for HostValidationRule
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp> // for PortValidationRule #include <webserv/config/validation/directive_rules/PortValidationRule.hpp> // for PortValidationRule
#include <webserv/config/validation/structural_rules/StructuralRules.hpp> // for structural rules #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/log/Log.hpp> // for LOCATION, Log #include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp> // for MinimumServerBlocksRule
#include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp> // for RequiredDirectivesRule
#include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp> // for RequiredLocationBlocksRule
#include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp> // for UniqueServerNamesRule
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <memory> #include <memory> // for unique_ptr, make_unique
#include <string> // for basic_string, string #include <string> // for basic_string, string
class ValidationResult;
ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make_unique<ValidationEngine>(config)) ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make_unique<ValidationEngine>(config))
{ {
Log::trace(LOCATION); Log::trace(LOCATION);

View File

@ -1,13 +1,16 @@
#include <webserv/config/validation/ValidationEngine.hpp>
#include <webserv/config/AConfig.hpp> // for AConfig #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig #include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/config/LocationConfig.hpp> // for LocationConfig #include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp> // for ServerConfig #include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/config/validation/ValidationEngine.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult #include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/log/Log.hpp> // for Log, LOCATION #include <webserv/log/Log.hpp> // for Log, LOCATION
#include <utility> // for move, get #include <exception> // for exception
#include <utility> // for move, get
void ValidationEngine::addGlobalRule(const std::string &directiveName, std::unique_ptr<AValidationRule> rule) void ValidationEngine::addGlobalRule(const std::string &directiveName, std::unique_ptr<AValidationRule> rule)
{ {
@ -136,8 +139,8 @@ void ValidationEngine::validateLocationConfig(const std::string &path, const Loc
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
results_.push_back(ValidationResult::error("Structural rule '" + rule->getRuleName() + results_.push_back(ValidationResult::error("Structural rule '" + rule->getRuleName()
"' threw exception for location '" + path + "': " + e.what())); + "' threw exception for location '" + path + "': " + e.what()));
} }
} }

View File

@ -1,6 +1,7 @@
#include <webserv/config/validation/directive_rules/AValidationRule.hpp>
#include <webserv/config/AConfig.hpp> // for AConfig #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp>
#include <webserv/log/Log.hpp> // for LOCATION, Log #include <webserv/log/Log.hpp> // for LOCATION, Log
#include <utility> // for move #include <utility> // for move

View File

@ -17,8 +17,8 @@ class AValidationRule
[[nodiscard]] ValidationResult validate(const AConfig *config, const std::string &directiveName) const; [[nodiscard]] ValidationResult validate(const AConfig *config, const std::string &directiveName) const;
[[nodiscard]] bool isRequired() const; [[nodiscard]] bool isRequired() const;
[[nodiscard]] virtual ValidationResult validateValue(const AConfig *config, [[nodiscard]] virtual ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const
const std::string &directiveName) const = 0; = 0;
[[nodiscard]] std::string getRuleName() const; [[nodiscard]] std::string getRuleName() const;
[[nodiscard]] std::string getDescription() const; [[nodiscard]] std::string getDescription() const;

View File

@ -6,11 +6,9 @@
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule #include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <functional> // for identity #include <ranges> // for __find_fn, find
#include <ranges> // for __find_fn, find #include <string> // for basic_string, allocator, operator+, char_traits, string
#include <string> // for basic_string, allocator, operator+, char_traits, string, operator== #include <vector> // for vector
#include <utility> // for move
#include <vector> // for vector
AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue) AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue)
: AValidationRule("AllowedValuesRule", "Ensures that the directive's value is within the allowed set", : AValidationRule("AllowedValuesRule", "Ensures that the directive's value is within the allowed set",

View File

@ -1,11 +1,14 @@
#include <webserv/config/validation/directive_rules/CgiExtValidationRule.hpp> #include <webserv/config/validation/directive_rules/CgiExtValidationRule.hpp>
#include <webserv/config/AConfig.hpp> #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/validation/ValidationResult.hpp> #include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/utils/FileUtils.hpp> #include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/utils/FileUtils.hpp> // for isFile
#include <algorithm> #include <algorithm> // for __any_of_fn, any_of
#include <vector> #include <vector> // for vector
CgiExtValidationRule::CgiExtValidationRule(bool requiresValue) CgiExtValidationRule::CgiExtValidationRule(bool requiresValue)
: AValidationRule("CgiExt", "Ensure CGI extension is valid", requiresValue) : AValidationRule("CgiExt", "Ensure CGI extension is valid", requiresValue)
@ -29,20 +32,20 @@ ValidationResult CgiExtValidationRule::validateValue(const AConfig *config, cons
auto cgiExt = directive->getValue().get<std::vector<std::string>>(); auto cgiExt = directive->getValue().get<std::vector<std::string>>();
if (cgiExt.size() != 2) if (cgiExt.size() != 2)
{ {
return ValidationResult::error("Directive '" + directive->getName() + return ValidationResult::error("Directive '" + directive->getName()
"' has invalid format, expected extension and path"); + "' has invalid format, expected extension and path");
} }
auto extension = std::string(cgiExt[0]); auto extension = std::string(cgiExt[0]);
auto path = std::string(cgiExt[1]); auto path = std::string(cgiExt[1]);
if (extension.empty() || extension[0] != '.') if (extension.empty() || extension[0] != '.')
{ {
return ValidationResult::error("Directive '" + directive->getName() + "' has invalid extension '" + extension + return ValidationResult::error("Directive '" + directive->getName() + "' has invalid extension '" + extension
"'"); + "'");
} }
if (!isAllowedCGIExtension(extension)) if (!isAllowedCGIExtension(extension))
{ {
return ValidationResult::error("Directive '" + directive->getName() + "' has unsupported extension '" + return ValidationResult::error("Directive '" + directive->getName() + "' has unsupported extension '"
extension + "'"); + extension + "'");
} }
if (!FileUtils::isFile(path)) if (!FileUtils::isFile(path))
{ {

View File

@ -1,7 +1,9 @@
#pragma once #pragma once
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult #include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <string> // for string
class CgiExtValidationRule : public AValidationRule class CgiExtValidationRule : public AValidationRule
{ {

View File

@ -1,4 +1,5 @@
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> #pragma once
#include <webserv/config/validation/directive_rules/AValidationRule.hpp>
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp> #include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp>
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp> #include <webserv/config/validation/directive_rules/PortValidationRule.hpp>

View File

@ -1,9 +1,12 @@
#include <webserv/config/validation/directive_rules/FolderExistsRule.hpp> #include <webserv/config/validation/directive_rules/FolderExistsRule.hpp>
#include <webserv/config/directive/ADirective.hpp> #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/validation/ValidationResult.hpp> #include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/log/Log.hpp> #include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
#include <webserv/utils/FileUtils.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/log/Log.hpp> // for Log
#include <webserv/utils/FileUtils.hpp> // for isDirectory
FolderExistsRule::FolderExistsRule(bool requiresValue) FolderExistsRule::FolderExistsRule(bool requiresValue)
: AValidationRule("FolderExists", "Ensures the specified folder exists", requiresValue) : AValidationRule("FolderExists", "Ensures the specified folder exists", requiresValue)

View File

@ -2,7 +2,9 @@
#include <webserv/config/AConfig.hpp> #include <webserv/config/AConfig.hpp>
#include <webserv/config/validation/ValidationResult.hpp> #include <webserv/config/validation/ValidationResult.hpp>
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> #include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <string> // for string
class FolderExistsRule : public AValidationRule class FolderExistsRule : public AValidationRule
{ {

View File

@ -1,13 +1,15 @@
#include <webserv/config/validation/directive_rules/HostValidationRule.hpp> #include <webserv/config/validation/directive_rules/HostValidationRule.hpp>
#include <webserv/config/AConfig.hpp> #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/directive/ADirective.hpp> #include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/validation/ValidationResult.hpp> #include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
#include <webserv/utils/utils.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/utils/utils.hpp> // for split
#include <cctype> #include <cctype> // for isdigit
#include <string> #include <string> // for basic_string, allocator, char_traits, operator+, string, stoi
#include <vector> #include <vector> // for vector
HostValidationRule::HostValidationRule(bool requiresValue) HostValidationRule::HostValidationRule(bool requiresValue)
: AValidationRule("HostValidationRule", "Validates that the host is a valid domain name", requiresValue) : AValidationRule("HostValidationRule", "Validates that the host is a valid domain name", requiresValue)

View File

@ -1,13 +1,16 @@
#include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp> #include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp>
#include <webserv/config/GlobalConfig.hpp> #include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/log/Log.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <string> #include <string> // for allocator, operator+, char_traits, to_string, basic_string
#include <vector> // for vector
MinimumServerBlocksRule::MinimumServerBlocksRule(size_t minimumServers) MinimumServerBlocksRule::MinimumServerBlocksRule(size_t minimumServers)
: AStructuralValidationRule("MinimumServerBlocksRule", "Ensures global config has at least " + : AStructuralValidationRule("MinimumServerBlocksRule", "Ensures global config has at least "
std::to_string(minimumServers) + " server block(s)"), + std::to_string(minimumServers) + " server block(s)"),
minimumServers_(minimumServers) minimumServers_(minimumServers)
{ {
} }
@ -25,8 +28,8 @@ ValidationResult MinimumServerBlocksRule::validateGlobal(const GlobalConfig *con
if (serverCount < minimumServers_) if (serverCount < minimumServers_)
{ {
return ValidationResult::error("Global configuration must have at least " + std::to_string(minimumServers_) + return ValidationResult::error("Global configuration must have at least " + std::to_string(minimumServers_)
" server block(s), but found " + std::to_string(serverCount)); + " server block(s), but found " + std::to_string(serverCount));
} }
return ValidationResult::success(); return ValidationResult::success();

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <cstddef> #include <cstddef> // for size_t
class GlobalConfig; class GlobalConfig;

View File

@ -1,13 +1,18 @@
#include <webserv/config/GlobalConfig.hpp>
#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/ServerConfig.hpp>
#include <webserv/config/directive/DirectiveFactory.hpp>
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp>
#include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp> #include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp>
#include <webserv/log/Log.hpp>
#include <webserv/utils/utils.hpp>
#include <cctype> #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/utils/utils.hpp> // for implode
#include <array> // for array
#include <cctype> // for toupper, tolower
#include <string> // for basic_string, allocator, char_traits, string, operator+
#include <vector> // for vector
RequiredDirectivesRule::RequiredDirectivesRule() RequiredDirectivesRule::RequiredDirectivesRule()
: AStructuralValidationRule("RequiredDirectivesRule", "Ensures required directives are present in each context") : AStructuralValidationRule("RequiredDirectivesRule", "Ensures required directives are present in each context")
@ -21,14 +26,16 @@ ValidationResult validateUniversal(const AConfig *config, std::string configType
for (const auto &directive : DirectiveFactory::supportedDirectives) for (const auto &directive : DirectiveFactory::supportedDirectives)
{ {
if (directive.context.find(static_cast<char>(std::toupper(configType[0]))) != std::string::npos && if (directive.context.find(static_cast<char>(std::toupper(configType[0]))) != std::string::npos
!config->owns(std::string(directive.name))) && !config->owns(std::string(directive.name)))
{ {
missingDirectives.emplace_back(directive.name); missingDirectives.emplace_back(directive.name);
} }
if ((directive.context.find(static_cast<char>(std::toupper(static_cast<unsigned char>(configType[0])))) == std::string::npos && if ((directive.context.find(static_cast<char>(std::toupper(static_cast<unsigned char>(configType[0]))))
directive.context.find(static_cast<char>(std::tolower(static_cast<unsigned char>(configType[0])))) == std::string::npos) && == std::string::npos
config->owns(std::string(directive.name))) && directive.context.find(static_cast<char>(std::tolower(static_cast<unsigned char>(configType[0]))))
== std::string::npos)
&& config->owns(std::string(directive.name)))
{ {
prohibitedDirectives.emplace_back(directive.name); prohibitedDirectives.emplace_back(directive.name);
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <cstddef> #include <cstddef>

View File

@ -1,14 +1,17 @@
#include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp> #include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp>
#include <webserv/config/ServerConfig.hpp> #include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/log/Log.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <string> #include <string> // for allocator, operator+, char_traits, to_string, basic_string
#include <vector> // for vector
RequiredLocationBlocksRule::RequiredLocationBlocksRule(size_t minimumLocations) RequiredLocationBlocksRule::RequiredLocationBlocksRule(size_t minimumLocations)
: AStructuralValidationRule("RequiredLocationBlocksRule", "Ensures server has at least " + : AStructuralValidationRule("RequiredLocationBlocksRule", "Ensures server has at least "
std::to_string(minimumLocations) + + std::to_string(minimumLocations)
" location block(s)"), + " location block(s)"),
minimumLocations_(minimumLocations) minimumLocations_(minimumLocations)
{ {
} }
@ -26,8 +29,8 @@ ValidationResult RequiredLocationBlocksRule::validateServer(const ServerConfig *
if (locationCount < minimumLocations_) if (locationCount < minimumLocations_)
{ {
return ValidationResult::error("Server block must have at least " + std::to_string(minimumLocations_) + return ValidationResult::error("Server block must have at least " + std::to_string(minimumLocations_)
" location block(s), but found " + std::to_string(locationCount)); + " location block(s), but found " + std::to_string(locationCount));
} }
return ValidationResult::success(); return ValidationResult::success();

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <cstddef> #include <cstddef> // for size_t
class ServerConfig; class ServerConfig;

View File

@ -5,6 +5,6 @@
// Concrete structural validation rules // Concrete structural validation rules
#include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp> #include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp>
#include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp>
#include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp> #include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp>
#include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp> #include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp>
#include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp>

View File

@ -1,12 +1,15 @@
#include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp> #include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp>
#include <webserv/config/GlobalConfig.hpp> #include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/config/ServerConfig.hpp> #include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/log/Log.hpp> #include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <optional> #include <optional> // for optional
#include <set> #include <set> // for set
#include <string> #include <string> // for basic_string, operator+, to_string, allocator, char_traits, string, operator<=>
#include <vector> // for vector
UniqueServerNamesRule::UniqueServerNamesRule() UniqueServerNamesRule::UniqueServerNamesRule()
: AStructuralValidationRule("UniqueServerNamesRule", "Ensures all server blocks have unique server names") : AStructuralValidationRule("UniqueServerNamesRule", "Ensures all server blocks have unique server names")

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> #include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
class GlobalConfig; class GlobalConfig;

View File

@ -1,16 +1,16 @@
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/config/AConfig.hpp> // for AConfig #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/ConfigManager.hpp> // for ConfigManager #include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig #include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler #include <webserv/http/HttpConstants.hpp> // for getStatusCodeReason, INTERNAL_SERVER_ERROR
#include <webserv/http/HttpConstants.hpp> // for StatusCodeInfo, CRLF, DOUBLE_CRLF, INTERNAL_SERVER_ERROR, statusCodeInfos #include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <webserv/http/HttpResponse.hpp> #include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/log/Log.hpp> // for Log
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream #include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
#include <memory> #include <memory> // for allocator, make_unique, unique_ptr
#include <sstream> // for basic_stringstream #include <sstream> // for basic_stringstream
#include <string> // for basic_string, operator+, allocator, char_traits, string, to_string #include <string> // for basic_string, char_traits, operator+, string, to_string
#include <sys/types.h>
std::unique_ptr<HttpResponse> ErrorHandler::getErrorResponse(uint16_t statusCode, const AConfig *config) std::unique_ptr<HttpResponse> ErrorHandler::getErrorResponse(uint16_t statusCode, const AConfig *config)
{ {
@ -51,9 +51,9 @@ std::string ErrorHandler::generateDefaultErrorPage(uint16_t statusCode)
{ {
Log::info("Generating default error page"); Log::info("Generating default error page");
std::string statusMessage = Http::getStatusCodeReason(statusCode); std::string statusMessage = Http::getStatusCodeReason(statusCode);
std::string html = "<html><head><title>" + std::to_string(statusCode) + " " + statusMessage + std::string html = "<html><head><title>" + std::to_string(statusCode) + " " + statusMessage
"</title></head><body><h1>" + std::to_string(statusCode) + " " + statusMessage + + "</title></head><body><h1>" + std::to_string(statusCode) + " " + statusMessage
"</h1><hr><p>webserv</p></body></html>"; + "</h1><hr><p>webserv</p></body></html>";
return html; return html;
} }

View File

@ -1,11 +1,16 @@
#pragma once #pragma once
#include <webserv/config/AConfig.hpp> #include <webserv/config/AConfig.hpp>
#include <webserv/http/HttpResponse.hpp> #include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <memory> #include <memory> // for unique_ptr
#include <string> // for string
#include <stdint.h> // for uint16_t
#include <sys/types.h> #include <sys/types.h>
class AConfig;
class ErrorHandler class ErrorHandler
{ {
public: public:

View File

@ -1,7 +1,7 @@
#include "webserv/config/AConfig.hpp"
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/FileHandler.hpp> #include <webserv/handler/FileHandler.hpp>
#include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/MIMETypes.hpp> // for MIMETypes #include <webserv/handler/MIMETypes.hpp> // for MIMETypes
#include <webserv/handler/URI.hpp> // for URI #include <webserv/handler/URI.hpp> // for URI
#include <webserv/http/HttpConstants.hpp> // for NOT_FOUND, FORBIDDEN, OK #include <webserv/http/HttpConstants.hpp> // for NOT_FOUND, FORBIDDEN, OK
@ -9,10 +9,11 @@
#include <webserv/log/Log.hpp> // for Log, LOCATION #include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isFile, readBinaryFile #include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isFile, readBinaryFile
#include <memory> // for unique_ptr, allocator, make_unique #include <memory> // for unique_ptr, allocator, make_unique
#include <ranges> #include <optional> // for optional
#include <string> // for basic_string, string, operator+, char_traits #include <ranges> // for __find_if_fn, find_if
#include <vector> // for vector #include <string> // for basic_string, string, operator+, char_traits
#include <vector> // for vector
FileHandler::FileHandler(const AConfig *config, const URI &URI) : config_(config), uri_(URI) FileHandler::FileHandler(const AConfig *config, const URI &URI) : config_(config), uri_(URI)
{ {

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "webserv/config/AConfig.hpp" #include <webserv/config/AConfig.hpp>
#include <webserv/config/LocationConfig.hpp> #include <webserv/config/LocationConfig.hpp>
#include <webserv/handler/URI.hpp> #include <webserv/handler/URI.hpp>
#include <webserv/http/HttpResponse.hpp> // for HttpResponse #include <webserv/http/HttpResponse.hpp> // for HttpResponse

View File

@ -1,5 +1,4 @@
#ifndef MIMETYPES_HPP #pragma once
#define MIMETYPES_HPP
#include <map> #include <map>
#include <string> #include <string>
@ -20,5 +19,3 @@ class MIMETypes
void initializeDefaults(); void initializeDefaults();
}; };
#endif // MIMETYPES_HPP

View File

@ -1,14 +1,15 @@
#include "webserv/config/AConfig.hpp"
#include "webserv/utils/FileUtils.hpp"
#include "webserv/utils/utils.hpp"
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/handler/URI.hpp> #include <webserv/handler/URI.hpp>
#include <optional> // for optional #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isDirectory, isFile, isValidPath
#include <webserv/utils/utils.hpp> // for trim, split
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <optional> // for optional, operator!=
#include <vector> // for vector
URI::URI(const HttpRequest &request, const ServerConfig &serverConfig) URI::URI(const HttpRequest &request, const ServerConfig &serverConfig)
: uriTrimmed_(utils::trim(request.getTarget(), "/")), config_(matchConfig(uriTrimmed_, serverConfig)) : uriTrimmed_(utils::trim(request.getTarget(), "/")), config_(matchConfig(uriTrimmed_, serverConfig))

View File

@ -1,16 +1,17 @@
#pragma once #pragma once
#include "webserv/config/AConfig.hpp" #include <webserv/config/AConfig.hpp>
#include "webserv/http/HttpRequest.hpp"
#include <webserv/config/LocationConfig.hpp> #include <webserv/config/LocationConfig.hpp>
#include <webserv/config/ServerConfig.hpp> #include <webserv/config/ServerConfig.hpp>
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
#include <webserv/server/Server.hpp> #include <webserv/server/Server.hpp>
#include <map> // for map
#include <string> // for string, basic_string #include <string> // for string, basic_string
class LocationConfig; class LocationConfig;
class ServerConfig; class ServerConfig;
class AConfig;
class URI class URI
{ {

View File

@ -52,19 +52,19 @@ struct StatusCodeInfo
std::string_view reason; std::string_view reason;
}; };
static constexpr std::array<StatusCodeInfo, 12> statusCodeInfos = { static constexpr std::array<StatusCodeInfo, 12> statusCodeInfos
{{.code = StatusCode::OK, .reason = "OK"}, = {{{.code = StatusCode::OK, .reason = "OK"},
{.code = StatusCode::CREATED, .reason = "Created"}, {.code = StatusCode::CREATED, .reason = "Created"},
{.code = StatusCode::NO_CONTENT, .reason = "No Content"}, {.code = StatusCode::NO_CONTENT, .reason = "No Content"},
{.code = StatusCode::BAD_REQUEST, .reason = "Bad Request"}, {.code = StatusCode::BAD_REQUEST, .reason = "Bad Request"},
{.code = StatusCode::UNAUTHORIZED, .reason = "Unauthorized"}, {.code = StatusCode::UNAUTHORIZED, .reason = "Unauthorized"},
{.code = StatusCode::FORBIDDEN, .reason = "Forbidden"}, {.code = StatusCode::FORBIDDEN, .reason = "Forbidden"},
{.code = StatusCode::NOT_FOUND, .reason = "Not Found"}, {.code = StatusCode::NOT_FOUND, .reason = "Not Found"},
{.code = StatusCode::METHOD_NOT_ALLOWED, .reason = "Method Not Allowed"}, {.code = StatusCode::METHOD_NOT_ALLOWED, .reason = "Method Not Allowed"},
{.code = StatusCode::INTERNAL_SERVER_ERROR, .reason = "Internal Server Error"}, {.code = StatusCode::INTERNAL_SERVER_ERROR, .reason = "Internal Server Error"},
{.code = StatusCode::NOT_IMPLEMENTED, .reason = "Not Implemented"}, {.code = StatusCode::NOT_IMPLEMENTED, .reason = "Not Implemented"},
{.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"}, {.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"},
{.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}}; {.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}};
std::string getStatusCodeReason(uint16_t statusCode); std::string getStatusCodeReason(uint16_t statusCode);

View File

@ -1,10 +1,9 @@
#include <webserv/http/HttpResponse.hpp> #include <webserv/http/HttpResponse.hpp>
#include <webserv/http/HttpConstants.hpp> #include <webserv/http/HttpConstants.hpp> // for getStatusCodeReason
#include <string> #include <string> // for basic_string, operator+, string, char_traits, to_string
#include <vector> #include <vector> // for vector
#include <sys/types.h>
HttpResponse::HttpResponse() : headers_(std::make_unique<HttpHeaders>()) {} HttpResponse::HttpResponse() : headers_(std::make_unique<HttpHeaders>()) {}

View File

@ -3,7 +3,7 @@
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders #include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for LOCATION, Log #include <webserv/log/Log.hpp> // for LOCATION, Log
#include <cstdint> // for uint8_t #include <cstdint> // for uint8_t, uint16_t
#include <memory> // for unique_ptr #include <memory> // for unique_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector

View File

@ -4,7 +4,6 @@
#include <sstream> // for basic_ostream, operator<<, basic_stringstream, basic_istream, basic_istringstream, right, istringstream, stringstream #include <sstream> // for basic_ostream, operator<<, basic_stringstream, basic_istream, basic_istringstream, right, istringstream, stringstream
#include <utility> // for get #include <utility> // for get
std::string Channel::printContext(const std::map<std::string, std::string> &context) std::string Channel::printContext(const std::map<std::string, std::string> &context)
{ {
std::stringstream ss; std::stringstream ss;

View File

@ -15,13 +15,11 @@ class Channel
Channel &operator=(const Channel &other) = delete; Channel &operator=(const Channel &other) = delete;
Channel &operator=(Channel &&other) = delete; Channel &operator=(Channel &&other) = delete;
virtual void log(const Log::Level &logLevel, const std::string &message, virtual void log(const Log::Level &logLevel, const std::string &message,
const std::map<std::string, std::string> &context = {}) = 0; const std::map<std::string, std::string> &context = {})
= 0;
protected: protected:
[[nodiscard]] static std::string printContext(const std::map<std::string, std::string> &context); [[nodiscard]] static std::string printContext(const std::map<std::string, std::string> &context);
private: private:
}; };

View File

@ -1,6 +1,7 @@
#include <webserv/log/Log.hpp>
#include <webserv/log/Channel.hpp> // for Channel #include <webserv/log/Channel.hpp> // for Channel
#include <webserv/log/FileChannel.hpp> // for FileChannel #include <webserv/log/FileChannel.hpp> // for FileChannel
#include <webserv/log/Log.hpp>
#include <webserv/log/StdoutChannel.hpp> // for StdoutChannel #include <webserv/log/StdoutChannel.hpp> // for StdoutChannel
#include <chrono> // for duration_cast, operator-, steady_clock, duration, seconds #include <chrono> // for duration_cast, operator-, steady_clock, duration, seconds

View File

@ -29,7 +29,6 @@ constexpr const char *extractFilename(const char *path)
#define LOCATION \ #define LOCATION \
(std::string(extractFilename(__FILE__)) + ":" + std::to_string(__LINE__) + " (" + std::string(__FUNCTION__) + ")") (std::string(extractFilename(__FILE__)) + ":" + std::to_string(__LINE__) + " (" + std::string(__FUNCTION__) + ")")
class Log class Log
{ {
public: public:
@ -38,7 +37,7 @@ class Log
Log &operator=(const Log &other) = delete; Log &operator=(const Log &other) = delete;
Log &operator=(Log &&other) = delete; Log &operator=(Log &&other) = delete;
enum class Level : uint8_t enum class Level : uint8_t
{ {
Trace = 0, Trace = 0,
Debug = 1, Debug = 1,
@ -85,15 +84,13 @@ class Log
const char *color; const char *color;
}; };
constexpr static std::array<LevelMapping, 6> LOG_LEVEL_MAP = { constexpr static std::array<LevelMapping, 6> LOG_LEVEL_MAP
{{.level = Log::Level::Trace, .name = "TRACE", .color = "\033[36m"}, = {{{.level = Log::Level::Trace, .name = "TRACE", .color = "\033[36m"},
{.level = Log::Level::Debug, .name = "DEBUG", .color = "\033[90m"}, {.level = Log::Level::Debug, .name = "DEBUG", .color = "\033[90m"},
{.level = Log::Level::Info, .name = "INFO", .color = "\033[37m"}, {.level = Log::Level::Info, .name = "INFO", .color = "\033[37m"},
{.level = Log::Level::Warn, .name = "WARN", .color = "\033[33m"}, {.level = Log::Level::Warn, .name = "WARN", .color = "\033[33m"},
{.level = Log::Level::Error, .name = "ERROR", .color = "\033[31m"}, {.level = Log::Level::Error, .name = "ERROR", .color = "\033[31m"},
{.level = Log::Level::Fatal, .name = "FATAL", .color = "\033[1;31m"}}}; {.level = Log::Level::Fatal, .name = "FATAL", .color = "\033[1;31m"}}};
constexpr static const char *RESET_COLOR = "\033[0m"; constexpr static const char *RESET_COLOR = "\033[0m";
}; };

View File

@ -5,8 +5,6 @@
#include <iomanip> // for operator<<, setfill, setw #include <iomanip> // for operator<<, setfill, setw
#include <iostream> // for basic_ostream, operator<<, basic_ostream::operator<<, cerr, cout, flush, ostream #include <iostream> // for basic_ostream, operator<<, basic_ostream::operator<<, cerr, cout, flush, ostream
void StdoutChannel::log(const Log::Level &logLevel, const std::string &message, void StdoutChannel::log(const Log::Level &logLevel, const std::string &message,
const std::map<std::string, std::string> &context) const std::map<std::string, std::string> &context)
{ {

View File

@ -8,9 +8,6 @@
#include <string> // for allocator, basic_string, char_traits, operator+, string #include <string> // for allocator, basic_string, char_traits, operator+, string
#include <vector> // for vector #include <vector> // for vector
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc < 2) if (argc < 2)

View File

@ -1,22 +1,22 @@
#include "webserv/config/AConfig.hpp"
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/config/directive/ADirective.hpp>
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/FileHandler.hpp> // for FileHandler
#include <webserv/handler/URI.hpp> // for URI
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <webserv/router/Router.hpp> #include <webserv/router/Router.hpp>
#include <algorithm> #include <webserv/config/AConfig.hpp> // for AConfig
#include <memory> // for unique_ptr #include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <optional> // for optional #include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <string> // for basic_string, string #include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
#include <vector> #include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/FileHandler.hpp> // for FileHandler
#include <webserv/handler/URI.hpp> // for URI
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for LOCATION, Log
class LocationConfig; #include <functional> // for identity
#include <memory> // for unique_ptr
#include <optional> // for optional
#include <ranges> // for __find_fn, find
#include <string> // for basic_string, string, operator==
#include <utility> // for move
#include <vector> // for vector
bool Router::isMethodSupported(const std::string &method, const AConfig &config) bool Router::isMethodSupported(const std::string &method, const AConfig &config)
{ {
@ -33,8 +33,8 @@ std::unique_ptr<HttpResponse> Router::handleRequest(const HttpRequest &request)
{ {
Log::trace(LOCATION); Log::trace(LOCATION);
ServerConfig *serverConfig = ServerConfig *serverConfig
ConfigManager::getInstance().getMatchingServerConfig(request.getHeaders().getHost().value_or("")); = ConfigManager::getInstance().getMatchingServerConfig(request.getHeaders().getHost().value_or(""));
if (serverConfig == nullptr) if (serverConfig == nullptr)
{ {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "webserv/config/AConfig.hpp" #include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/LocationConfig.hpp> #include <webserv/config/LocationConfig.hpp>
#include <webserv/http/HttpRequest.hpp> // for HttpRequest #include <webserv/http/HttpRequest.hpp> // for HttpRequest
#include <webserv/http/HttpResponse.hpp> // for HttpResponse #include <webserv/http/HttpResponse.hpp> // for HttpResponse

View File

@ -224,8 +224,8 @@ void Server::eventLoop()
ssize_t bytesSent = send(event.data.fd, httpResponse.data(), httpResponse.size(), 0); ssize_t bytesSent = send(event.data.fd, httpResponse.data(), httpResponse.size(), 0);
if (bytesSent < 0) if (bytesSent < 0)
{ {
Log::error("Send failed for fd: " + std::to_string(event.data.fd) + Log::error("Send failed for fd: " + std::to_string(event.data.fd)
" with error: " + std::strerror(errno)); + " with error: " + std::strerror(errno));
} }
else else
{ {

View File

@ -68,10 +68,11 @@ void Socket::bind(const std::string &host, const int port) const
address.sin_addr.s_addr = inet_addr(host.c_str()); address.sin_addr.s_addr = inet_addr(host.c_str());
address.sin_port = htons(port); address.sin_port = htons(port);
if (::bind(fd_, reinterpret_cast<struct sockaddr *>(&address), sizeof(address)) < 0) //NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) if (::bind(fd_, reinterpret_cast<struct sockaddr *>(&address), sizeof(address))
< 0) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
{ {
Log::fatal("Cannot bind to " + host + ":" + std::to_string(port) + Log::fatal("Cannot bind to " + host + ":" + std::to_string(port)
" - address already in use or permission denied"); + " - address already in use or permission denied");
throw std::runtime_error("Bind failed"); throw std::runtime_error("Bind failed");
} }
} }

View File

@ -1,6 +1,7 @@
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/FileUtils.hpp> #include <webserv/utils/FileUtils.hpp>
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <cstring> // for size_t #include <cstring> // for size_t
#include <fstream> // for basic_ifstream, basic_ios, basic_istream, ios, ifstream, operator|, basic_istream::read, basic_istream::seekg, basic_istream::tellg, streamsize #include <fstream> // for basic_ifstream, basic_ios, basic_istream, ios, ifstream, operator|, basic_istream::read, basic_istream::seekg, basic_istream::tellg, streamsize
#include <iterator> // for istreambuf_iterator, operator== #include <iterator> // for istreambuf_iterator, operator==