moved sites to htdocs and ran format script
This commit is contained in:
parent
fc1340ac7f
commit
4614a2d382
@ -1,17 +1,17 @@
|
||||
autoindex on
|
||||
error_page 400 ./error_pages/400.html
|
||||
error_page 500 ./error_pages/500.html
|
||||
error_page 400 ./htdocs/error_pages/400.html
|
||||
error_page 500 ./htdocs/error_pages/500.html
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
host 0.0.0.0;
|
||||
server_name localhost;
|
||||
|
||||
root ./www/;
|
||||
root ./htdocs/site-1/;
|
||||
index index.html index.htm;
|
||||
|
||||
error_page 400 /400.html;
|
||||
error_page 404 ./error_pages/404.html;
|
||||
error_page 400 ./htdocs/error_pages/400.html;
|
||||
error_page 404 ./htdocs/error_pages/404.html;
|
||||
error_page 403 /403.html;
|
||||
error_page 404 /404.html;
|
||||
error_page 405 /405.html;
|
||||
@ -24,7 +24,7 @@ server {
|
||||
|
||||
location / {
|
||||
autoindex off;
|
||||
root ./static_site/;
|
||||
root ./htdocs/site-1/;
|
||||
index index2.html index.html;
|
||||
allowed_methods GET POST DELETE;
|
||||
}
|
||||
@ -36,7 +36,7 @@ server {
|
||||
# }
|
||||
|
||||
location /images {
|
||||
root ./static_site/img;
|
||||
root ./htdocs/site-1/img;
|
||||
autoindex off;
|
||||
index index.jpg;
|
||||
allowed_methods GET;
|
||||
@ -51,7 +51,7 @@ server {
|
||||
host 127.0.0.1;
|
||||
server_name localhost;
|
||||
|
||||
root ./www;
|
||||
root ./htdocs/site-2/;
|
||||
index index.html index2.htm;
|
||||
|
||||
error_page 400;
|
||||
@ -67,7 +67,7 @@ server {
|
||||
|
||||
location / {
|
||||
autoindex off;
|
||||
root www;
|
||||
root ./htdocs/site-2/;
|
||||
index index.html;
|
||||
allowed_methods GET POST DELETE;
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 151 KiB |
@ -78,7 +78,7 @@ TEST_F(LogTest, LogLevelToColoredString)
|
||||
|
||||
TEST_F(LogTest, StdoutChannelConstruction)
|
||||
{
|
||||
StdoutChannel channel();
|
||||
StdoutChannel channel;
|
||||
// If we reach here without exception, construction was successful
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
#include <sys/types.h> // for ssize_t
|
||||
|
||||
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)),
|
||||
server_(std::ref(server))
|
||||
: httpRequest_(std::make_unique<HttpRequest>(this)), httpResponse_(std::make_unique<HttpResponse>()),
|
||||
client_socket_(std::move(socket)), server_(std::ref(server))
|
||||
{
|
||||
Log::trace(LOCATION);
|
||||
Log::info("New client connected, fd: " + std::to_string(client_socket_->getFd()));
|
||||
@ -45,8 +45,8 @@ void Client::request()
|
||||
{
|
||||
Log::trace(LOCATION);
|
||||
char buffer[bufferSize_] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays)
|
||||
ssize_t bytesRead =
|
||||
client_socket_->recv(buffer, sizeof(buffer) - 1); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
|
||||
ssize_t bytesRead = client_socket_->recv(
|
||||
buffer, sizeof(buffer) - 1); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
Log::error("Read error");
|
||||
@ -62,8 +62,8 @@ void Client::request()
|
||||
buffer[bytesRead] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
|
||||
httpRequest_->receiveData(static_cast<const char *>(buffer), static_cast<size_t>(bytesRead));
|
||||
|
||||
if (httpRequest_->getState() == HttpRequest::State::Complete ||
|
||||
httpRequest_->getState() == HttpRequest::State::ParseError)
|
||||
if (httpRequest_->getState() == HttpRequest::State::Complete
|
||||
|| httpRequest_->getState() == HttpRequest::State::ParseError)
|
||||
{
|
||||
Log::info("Received complete request",
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||
@ -52,7 +53,7 @@ bool AConfig::has(const std::string &name) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (parent_ != nullptr)
|
||||
{
|
||||
return parent_->has(name);
|
||||
|
||||
@ -18,8 +18,8 @@ ServerConfig::ServerConfig(const std::string &block, const AConfig *parent) : AC
|
||||
|
||||
std::string ServerConfig::getName() const
|
||||
{
|
||||
return "server: " + get<std::string>("server_name").value_or("unnamed") + " (port " +
|
||||
std::to_string(get<int>("listen").value_or(-1)) + ")";
|
||||
return "server: " + get<std::string>("server_name").value_or("unnamed") + " (port "
|
||||
+ std::to_string(get<int>("listen").value_or(-1)) + ")";
|
||||
}
|
||||
|
||||
std::string ServerConfig::getType() const
|
||||
@ -45,8 +45,8 @@ void ServerConfig::parseBlock(const std::string &block)
|
||||
directives += block.substr(pos);
|
||||
break;
|
||||
}
|
||||
std::string locationPath =
|
||||
utils::trim(block.substr(locationPos + 9, bracePos - (locationPos + 9))); // TODO magic numbers
|
||||
std::string locationPath
|
||||
= utils::trim(block.substr(locationPos + 9, bracePos - (locationPos + 9))); // TODO magic numbers
|
||||
// Add global declarations before this server block
|
||||
directives += block.substr(pos, locationPos - pos);
|
||||
size_t closeBrace = utils::findCorrespondingClosingBrace(block, bracePos);
|
||||
|
||||
@ -20,7 +20,6 @@ class DirectiveFactory
|
||||
std::string_view context;
|
||||
};
|
||||
|
||||
|
||||
constexpr static std::array<DirectiveInfo, 15> supportedDirectives = {{
|
||||
{.name = "listen", .type = "IntDirective", .context = "S"},
|
||||
{.name = "host", .type = "StringDirective", .context = "S"},
|
||||
@ -38,13 +37,10 @@ class DirectiveFactory
|
||||
{.name = "upload_store", .type = "StringDirective", .context = "gsl"},
|
||||
{.name = "redirect", .type = "VectorDirective", .context = "l"},
|
||||
}};
|
||||
|
||||
private:
|
||||
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 std::unique_ptr<ADirective> create(std::string_view type, const std::string &name, const std::string &arg);
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
@ -1,18 +1,24 @@
|
||||
#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/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp> // for AllowedValuesRule
|
||||
#include <webserv/config/validation/directive_rules/FolderExistsRule.hpp>
|
||||
#include <webserv/config/validation/directive_rules/HostValidationRule.hpp>
|
||||
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp> // for PortValidationRule
|
||||
#include <webserv/config/validation/structural_rules/StructuralRules.hpp> // for structural rules
|
||||
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||
#include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine
|
||||
#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/CgiExtValidationRule.hpp> // for CgiExtValidationRule
|
||||
#include <webserv/config/validation/directive_rules/FolderExistsRule.hpp> // for FolderExistsRule
|
||||
#include <webserv/config/validation/directive_rules/HostValidationRule.hpp> // for HostValidationRule
|
||||
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp> // for PortValidationRule
|
||||
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
|
||||
#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
|
||||
|
||||
class ValidationResult;
|
||||
|
||||
ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make_unique<ValidationEngine>(config))
|
||||
{
|
||||
Log::trace(LOCATION);
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
#include <webserv/config/validation/ValidationEngine.hpp>
|
||||
|
||||
#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/validation/ValidationEngine.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, LOCATION
|
||||
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||
#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 <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)
|
||||
{
|
||||
@ -136,8 +139,8 @@ void ValidationEngine::validateLocationConfig(const std::string &path, const Loc
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
results_.push_back(ValidationResult::error("Structural rule '" + rule->getRuleName() +
|
||||
"' threw exception for location '" + path + "': " + e.what()));
|
||||
results_.push_back(ValidationResult::error("Structural rule '" + rule->getRuleName()
|
||||
+ "' threw exception for location '" + path + "': " + e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <webserv/config/validation/directive_rules/AValidationRule.hpp>
|
||||
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#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 <utility> // for move
|
||||
|
||||
@ -17,8 +17,8 @@ class AValidationRule
|
||||
|
||||
[[nodiscard]] ValidationResult validate(const AConfig *config, const std::string &directiveName) const;
|
||||
[[nodiscard]] bool isRequired() const;
|
||||
[[nodiscard]] virtual ValidationResult validateValue(const AConfig *config,
|
||||
const std::string &directiveName) const = 0;
|
||||
[[nodiscard]] virtual ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const
|
||||
= 0;
|
||||
[[nodiscard]] std::string getRuleName() const;
|
||||
[[nodiscard]] std::string getDescription() const;
|
||||
|
||||
|
||||
@ -6,11 +6,9 @@
|
||||
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||
|
||||
#include <functional> // for identity
|
||||
#include <ranges> // for __find_fn, find
|
||||
#include <string> // for basic_string, allocator, operator+, char_traits, string, operator==
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
#include <ranges> // for __find_fn, find
|
||||
#include <string> // for basic_string, allocator, operator+, char_traits, string
|
||||
#include <vector> // for vector
|
||||
|
||||
AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue)
|
||||
: AValidationRule("AllowedValuesRule", "Ensures that the directive's value is within the allowed set",
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
#include <webserv/config/validation/directive_rules/CgiExtValidationRule.hpp>
|
||||
|
||||
#include <webserv/config/AConfig.hpp>
|
||||
#include <webserv/config/validation/ValidationResult.hpp>
|
||||
#include <webserv/utils/FileUtils.hpp>
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#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 <vector>
|
||||
#include <algorithm> // for __any_of_fn, any_of
|
||||
#include <vector> // for vector
|
||||
|
||||
CgiExtValidationRule::CgiExtValidationRule(bool 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>>();
|
||||
if (cgiExt.size() != 2)
|
||||
{
|
||||
return ValidationResult::error("Directive '" + directive->getName() +
|
||||
"' has invalid format, expected extension and path");
|
||||
return ValidationResult::error("Directive '" + directive->getName()
|
||||
+ "' has invalid format, expected extension and path");
|
||||
}
|
||||
auto extension = std::string(cgiExt[0]);
|
||||
auto path = std::string(cgiExt[1]);
|
||||
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))
|
||||
{
|
||||
return ValidationResult::error("Directive '" + directive->getName() + "' has unsupported extension '" +
|
||||
extension + "'");
|
||||
return ValidationResult::error("Directive '" + directive->getName() + "' has unsupported extension '"
|
||||
+ extension + "'");
|
||||
}
|
||||
if (!FileUtils::isFile(path))
|
||||
{
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
#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
|
||||
{
|
||||
|
||||
@ -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/PortValidationRule.hpp>
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
#include <webserv/config/validation/directive_rules/FolderExistsRule.hpp>
|
||||
|
||||
#include <webserv/config/directive/ADirective.hpp>
|
||||
#include <webserv/config/validation/ValidationResult.hpp>
|
||||
#include <webserv/log/Log.hpp>
|
||||
#include <webserv/utils/FileUtils.hpp>
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#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/log/Log.hpp> // for Log
|
||||
#include <webserv/utils/FileUtils.hpp> // for isDirectory
|
||||
|
||||
FolderExistsRule::FolderExistsRule(bool requiresValue)
|
||||
: AValidationRule("FolderExists", "Ensures the specified folder exists", requiresValue)
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
|
||||
#include <webserv/config/AConfig.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
|
||||
{
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
#include <webserv/config/validation/directive_rules/HostValidationRule.hpp>
|
||||
|
||||
#include <webserv/config/AConfig.hpp>
|
||||
#include <webserv/config/directive/ADirective.hpp>
|
||||
#include <webserv/config/validation/ValidationResult.hpp>
|
||||
#include <webserv/utils/utils.hpp>
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#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/utils.hpp> // for split
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cctype> // for isdigit
|
||||
#include <string> // for basic_string, allocator, char_traits, operator+, string, stoi
|
||||
#include <vector> // for vector
|
||||
|
||||
HostValidationRule::HostValidationRule(bool requiresValue)
|
||||
: AValidationRule("HostValidationRule", "Validates that the host is a valid domain name", requiresValue)
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
#include <webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp>
|
||||
|
||||
#include <webserv/config/GlobalConfig.hpp>
|
||||
#include <webserv/log/Log.hpp>
|
||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||
#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)
|
||||
: AStructuralValidationRule("MinimumServerBlocksRule", "Ensures global config has at least " +
|
||||
std::to_string(minimumServers) + " server block(s)"),
|
||||
: AStructuralValidationRule("MinimumServerBlocksRule", "Ensures global config has at least "
|
||||
+ std::to_string(minimumServers) + " server block(s)"),
|
||||
minimumServers_(minimumServers)
|
||||
{
|
||||
}
|
||||
@ -25,8 +28,8 @@ ValidationResult MinimumServerBlocksRule::validateGlobal(const GlobalConfig *con
|
||||
|
||||
if (serverCount < minimumServers_)
|
||||
{
|
||||
return ValidationResult::error("Global configuration must have at least " + std::to_string(minimumServers_) +
|
||||
" server block(s), but found " + std::to_string(serverCount));
|
||||
return ValidationResult::error("Global configuration must have at least " + std::to_string(minimumServers_)
|
||||
+ " server block(s), but found " + std::to_string(serverCount));
|
||||
}
|
||||
|
||||
return ValidationResult::success();
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#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;
|
||||
|
||||
|
||||
@ -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/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()
|
||||
: 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)
|
||||
{
|
||||
if (directive.context.find(static_cast<char>(std::toupper(configType[0]))) != std::string::npos &&
|
||||
!config->owns(std::string(directive.name)))
|
||||
if (directive.context.find(static_cast<char>(std::toupper(configType[0]))) != std::string::npos
|
||||
&& !config->owns(std::string(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 &&
|
||||
directive.context.find(static_cast<char>(std::tolower(static_cast<unsigned char>(configType[0])))) == std::string::npos) &&
|
||||
config->owns(std::string(directive.name)))
|
||||
if ((directive.context.find(static_cast<char>(std::toupper(static_cast<unsigned char>(configType[0]))))
|
||||
== std::string::npos
|
||||
&& 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);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp>
|
||||
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
#include <webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp>
|
||||
|
||||
#include <webserv/config/ServerConfig.hpp>
|
||||
#include <webserv/log/Log.hpp>
|
||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||
#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)
|
||||
: AStructuralValidationRule("RequiredLocationBlocksRule", "Ensures server has at least " +
|
||||
std::to_string(minimumLocations) +
|
||||
" location block(s)"),
|
||||
: AStructuralValidationRule("RequiredLocationBlocksRule", "Ensures server has at least "
|
||||
+ std::to_string(minimumLocations)
|
||||
+ " location block(s)"),
|
||||
minimumLocations_(minimumLocations)
|
||||
{
|
||||
}
|
||||
@ -26,8 +29,8 @@ ValidationResult RequiredLocationBlocksRule::validateServer(const ServerConfig *
|
||||
|
||||
if (locationCount < minimumLocations_)
|
||||
{
|
||||
return ValidationResult::error("Server block must have at least " + std::to_string(minimumLocations_) +
|
||||
" location block(s), but found " + std::to_string(locationCount));
|
||||
return ValidationResult::error("Server block must have at least " + std::to_string(minimumLocations_)
|
||||
+ " location block(s), but found " + std::to_string(locationCount));
|
||||
}
|
||||
|
||||
return ValidationResult::success();
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#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;
|
||||
|
||||
|
||||
@ -5,6 +5,6 @@
|
||||
|
||||
// Concrete structural validation rules
|
||||
#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/UniqueServerNamesRule.hpp>
|
||||
#include <webserv/config/validation/structural_rules/RequiredDirectivesRule.hpp>
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
#include <webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp>
|
||||
|
||||
#include <webserv/config/GlobalConfig.hpp>
|
||||
#include <webserv/config/ServerConfig.hpp>
|
||||
#include <webserv/log/Log.hpp>
|
||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||
#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 <set>
|
||||
#include <string>
|
||||
#include <optional> // for optional
|
||||
#include <set> // for set
|
||||
#include <string> // for basic_string, operator+, to_string, allocator, char_traits, string, operator<=>
|
||||
#include <vector> // for vector
|
||||
|
||||
UniqueServerNamesRule::UniqueServerNamesRule()
|
||||
: AStructuralValidationRule("UniqueServerNamesRule", "Ensures all server blocks have unique server names")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp>
|
||||
#include <webserv/config/validation/structural_rules/AStructuralValidationRule.hpp> // for AStructuralValidationRule
|
||||
|
||||
class GlobalConfig;
|
||||
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||
#include <webserv/http/HttpConstants.hpp> // for StatusCodeInfo, CRLF, DOUBLE_CRLF, INTERNAL_SERVER_ERROR, statusCodeInfos
|
||||
#include <webserv/http/HttpResponse.hpp>
|
||||
#include <webserv/log/Log.hpp> // for Log
|
||||
#include <webserv/http/HttpConstants.hpp> // for getStatusCodeReason, INTERNAL_SERVER_ERROR
|
||||
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||
|
||||
#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 <string> // for basic_string, operator+, allocator, char_traits, string, to_string
|
||||
#include <sys/types.h>
|
||||
#include <string> // for basic_string, char_traits, operator+, string, to_string
|
||||
|
||||
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");
|
||||
std::string statusMessage = Http::getStatusCodeReason(statusCode);
|
||||
std::string html = "<html><head><title>" + std::to_string(statusCode) + " " + statusMessage +
|
||||
"</title></head><body><h1>" + std::to_string(statusCode) + " " + statusMessage +
|
||||
"</h1><hr><p>webserv</p></body></html>";
|
||||
std::string html = "<html><head><title>" + std::to_string(statusCode) + " " + statusMessage
|
||||
+ "</title></head><body><h1>" + std::to_string(statusCode) + " " + statusMessage
|
||||
+ "</h1><hr><p>webserv</p></body></html>";
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#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>
|
||||
|
||||
class AConfig;
|
||||
|
||||
class ErrorHandler
|
||||
{
|
||||
public:
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "webserv/config/AConfig.hpp"
|
||||
|
||||
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||
#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/URI.hpp> // for URI
|
||||
#include <webserv/http/HttpConstants.hpp> // for NOT_FOUND, FORBIDDEN, OK
|
||||
@ -9,10 +9,11 @@
|
||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||
#include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isFile, readBinaryFile
|
||||
|
||||
#include <memory> // for unique_ptr, allocator, make_unique
|
||||
#include <ranges>
|
||||
#include <string> // for basic_string, string, operator+, char_traits
|
||||
#include <vector> // for vector
|
||||
#include <memory> // for unique_ptr, allocator, make_unique
|
||||
#include <optional> // for optional
|
||||
#include <ranges> // for __find_if_fn, find_if
|
||||
#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)
|
||||
{
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "webserv/config/AConfig.hpp"
|
||||
|
||||
#include <webserv/config/AConfig.hpp>
|
||||
#include <webserv/config/LocationConfig.hpp>
|
||||
#include <webserv/handler/URI.hpp>
|
||||
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#ifndef MIMETYPES_HPP
|
||||
#define MIMETYPES_HPP
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@ -20,5 +19,3 @@ class MIMETypes
|
||||
|
||||
void initializeDefaults();
|
||||
};
|
||||
|
||||
#endif // MIMETYPES_HPP
|
||||
@ -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 <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)
|
||||
: uriTrimmed_(utils::trim(request.getTarget(), "/")), config_(matchConfig(uriTrimmed_, serverConfig))
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "webserv/config/AConfig.hpp"
|
||||
#include "webserv/http/HttpRequest.hpp"
|
||||
|
||||
#include <webserv/config/AConfig.hpp>
|
||||
#include <webserv/config/LocationConfig.hpp>
|
||||
#include <webserv/config/ServerConfig.hpp>
|
||||
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
|
||||
#include <webserv/server/Server.hpp>
|
||||
|
||||
#include <map> // for map
|
||||
#include <string> // for string, basic_string
|
||||
|
||||
class LocationConfig;
|
||||
class ServerConfig;
|
||||
class AConfig;
|
||||
|
||||
class URI
|
||||
{
|
||||
|
||||
@ -52,19 +52,19 @@ struct StatusCodeInfo
|
||||
std::string_view reason;
|
||||
};
|
||||
|
||||
static constexpr std::array<StatusCodeInfo, 12> statusCodeInfos = {
|
||||
{{.code = StatusCode::OK, .reason = "OK"},
|
||||
{.code = StatusCode::CREATED, .reason = "Created"},
|
||||
{.code = StatusCode::NO_CONTENT, .reason = "No Content"},
|
||||
{.code = StatusCode::BAD_REQUEST, .reason = "Bad Request"},
|
||||
{.code = StatusCode::UNAUTHORIZED, .reason = "Unauthorized"},
|
||||
{.code = StatusCode::FORBIDDEN, .reason = "Forbidden"},
|
||||
{.code = StatusCode::NOT_FOUND, .reason = "Not Found"},
|
||||
{.code = StatusCode::METHOD_NOT_ALLOWED, .reason = "Method Not Allowed"},
|
||||
{.code = StatusCode::INTERNAL_SERVER_ERROR, .reason = "Internal Server Error"},
|
||||
{.code = StatusCode::NOT_IMPLEMENTED, .reason = "Not Implemented"},
|
||||
{.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"},
|
||||
{.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}};
|
||||
static constexpr std::array<StatusCodeInfo, 12> statusCodeInfos
|
||||
= {{{.code = StatusCode::OK, .reason = "OK"},
|
||||
{.code = StatusCode::CREATED, .reason = "Created"},
|
||||
{.code = StatusCode::NO_CONTENT, .reason = "No Content"},
|
||||
{.code = StatusCode::BAD_REQUEST, .reason = "Bad Request"},
|
||||
{.code = StatusCode::UNAUTHORIZED, .reason = "Unauthorized"},
|
||||
{.code = StatusCode::FORBIDDEN, .reason = "Forbidden"},
|
||||
{.code = StatusCode::NOT_FOUND, .reason = "Not Found"},
|
||||
{.code = StatusCode::METHOD_NOT_ALLOWED, .reason = "Method Not Allowed"},
|
||||
{.code = StatusCode::INTERNAL_SERVER_ERROR, .reason = "Internal Server Error"},
|
||||
{.code = StatusCode::NOT_IMPLEMENTED, .reason = "Not Implemented"},
|
||||
{.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"},
|
||||
{.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}};
|
||||
|
||||
std::string getStatusCodeReason(uint16_t statusCode);
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
#include <webserv/http/HttpResponse.hpp>
|
||||
|
||||
#include <webserv/http/HttpConstants.hpp>
|
||||
#include <webserv/http/HttpConstants.hpp> // for getStatusCodeReason
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
#include <string> // for basic_string, operator+, string, char_traits, to_string
|
||||
#include <vector> // for vector
|
||||
|
||||
HttpResponse::HttpResponse() : headers_(std::make_unique<HttpHeaders>()) {}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||
#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 <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include <sstream> // for basic_ostream, operator<<, basic_stringstream, basic_istream, basic_istringstream, right, istringstream, stringstream
|
||||
#include <utility> // for get
|
||||
|
||||
|
||||
std::string Channel::printContext(const std::map<std::string, std::string> &context)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
@ -15,13 +15,11 @@ class Channel
|
||||
Channel &operator=(const Channel &other) = delete;
|
||||
Channel &operator=(Channel &&other) = delete;
|
||||
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:
|
||||
|
||||
[[nodiscard]] static std::string printContext(const std::map<std::string, std::string> &context);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
#include <webserv/log/Log.hpp>
|
||||
|
||||
#include <webserv/log/Channel.hpp> // for Channel
|
||||
#include <webserv/log/FileChannel.hpp> // for FileChannel
|
||||
#include <webserv/log/Log.hpp>
|
||||
#include <webserv/log/StdoutChannel.hpp> // for StdoutChannel
|
||||
|
||||
#include <chrono> // for duration_cast, operator-, steady_clock, duration, seconds
|
||||
|
||||
@ -29,7 +29,6 @@ constexpr const char *extractFilename(const char *path)
|
||||
#define LOCATION \
|
||||
(std::string(extractFilename(__FILE__)) + ":" + std::to_string(__LINE__) + " (" + std::string(__FUNCTION__) + ")")
|
||||
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
@ -38,7 +37,7 @@ class Log
|
||||
Log &operator=(const Log &other) = delete;
|
||||
Log &operator=(Log &&other) = delete;
|
||||
|
||||
enum class Level : uint8_t
|
||||
enum class Level : uint8_t
|
||||
{
|
||||
Trace = 0,
|
||||
Debug = 1,
|
||||
@ -85,15 +84,13 @@ class Log
|
||||
const char *color;
|
||||
};
|
||||
|
||||
constexpr static std::array<LevelMapping, 6> LOG_LEVEL_MAP = {
|
||||
{{.level = Log::Level::Trace, .name = "TRACE", .color = "\033[36m"},
|
||||
{.level = Log::Level::Debug, .name = "DEBUG", .color = "\033[90m"},
|
||||
{.level = Log::Level::Info, .name = "INFO", .color = "\033[37m"},
|
||||
{.level = Log::Level::Warn, .name = "WARN", .color = "\033[33m"},
|
||||
{.level = Log::Level::Error, .name = "ERROR", .color = "\033[31m"},
|
||||
{.level = Log::Level::Fatal, .name = "FATAL", .color = "\033[1;31m"}}};
|
||||
constexpr static std::array<LevelMapping, 6> LOG_LEVEL_MAP
|
||||
= {{{.level = Log::Level::Trace, .name = "TRACE", .color = "\033[36m"},
|
||||
{.level = Log::Level::Debug, .name = "DEBUG", .color = "\033[90m"},
|
||||
{.level = Log::Level::Info, .name = "INFO", .color = "\033[37m"},
|
||||
{.level = Log::Level::Warn, .name = "WARN", .color = "\033[33m"},
|
||||
{.level = Log::Level::Error, .name = "ERROR", .color = "\033[31m"},
|
||||
{.level = Log::Level::Fatal, .name = "FATAL", .color = "\033[1;31m"}}};
|
||||
|
||||
constexpr static const char *RESET_COLOR = "\033[0m";
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
#include <iomanip> // for operator<<, setfill, setw
|
||||
#include <iostream> // for basic_ostream, operator<<, basic_ostream::operator<<, cerr, cout, flush, ostream
|
||||
|
||||
|
||||
|
||||
void StdoutChannel::log(const Log::Level &logLevel, const std::string &message,
|
||||
const std::map<std::string, std::string> &context)
|
||||
{
|
||||
|
||||
@ -8,9 +8,6 @@
|
||||
#include <string> // for allocator, basic_string, char_traits, operator+, string
|
||||
#include <vector> // for vector
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
|
||||
@ -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 <algorithm>
|
||||
#include <memory> // for unique_ptr
|
||||
#include <optional> // for optional
|
||||
#include <string> // for basic_string, string
|
||||
#include <vector>
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||
#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)
|
||||
{
|
||||
@ -33,8 +33,8 @@ std::unique_ptr<HttpResponse> Router::handleRequest(const HttpRequest &request)
|
||||
{
|
||||
Log::trace(LOCATION);
|
||||
|
||||
ServerConfig *serverConfig =
|
||||
ConfigManager::getInstance().getMatchingServerConfig(request.getHeaders().getHost().value_or(""));
|
||||
ServerConfig *serverConfig
|
||||
= ConfigManager::getInstance().getMatchingServerConfig(request.getHeaders().getHost().value_or(""));
|
||||
|
||||
if (serverConfig == nullptr)
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "webserv/config/AConfig.hpp"
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/LocationConfig.hpp>
|
||||
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
|
||||
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||
|
||||
@ -224,8 +224,8 @@ void Server::eventLoop()
|
||||
ssize_t bytesSent = send(event.data.fd, httpResponse.data(), httpResponse.size(), 0);
|
||||
if (bytesSent < 0)
|
||||
{
|
||||
Log::error("Send failed for fd: " + std::to_string(event.data.fd) +
|
||||
" with error: " + std::strerror(errno));
|
||||
Log::error("Send failed for fd: " + std::to_string(event.data.fd)
|
||||
+ " with error: " + std::strerror(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -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_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) +
|
||||
" - address already in use or permission denied");
|
||||
Log::fatal("Cannot bind to " + host + ":" + std::to_string(port)
|
||||
+ " - address already in use or permission denied");
|
||||
throw std::runtime_error("Bind failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||
#include <webserv/utils/FileUtils.hpp>
|
||||
|
||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||
|
||||
#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 <iterator> // for istreambuf_iterator, operator==
|
||||
|
||||
Loading…
Reference in New Issue
Block a user