moving some files and fixing includes

This commit is contained in:
whaffman 2025-10-06 15:16:53 +02:00
parent 95753eea34
commit 010ee3e8b6
54 changed files with 393 additions and 320 deletions

View File

@ -1,20 +1,18 @@
#include "webserv/router/Router.hpp"
#include <webserv/client/Client.hpp>
#include <webserv/config/ConfigManager.hpp>
#include <webserv/config/ServerConfig.hpp>
#include <webserv/handler/ErrorHandler.hpp>
#include <webserv/http/HttpHeaders.hpp>
#include <webserv/log/Log.hpp>
#include <webserv/server/Server.hpp>
#include <webserv/socket/Socket.hpp>
#include <cstdint>
#include <functional>
#include <map>
#include <utility>
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/router/Router.hpp> // for Router
#include <webserv/server/Server.hpp> // for Server
#include <webserv/socket/Socket.hpp> // for Socket
#include <sys/types.h>
#include <cstdint> // for uint8_t
#include <functional> // for ref, reference_wrapper
#include <map> // for map
#include <string> // for basic_string, to_string, operator+, operator<=>
#include <utility> // for pair, move
#include <sys/types.h> // for ssize_t
Client::Client(std::unique_ptr<Socket> socket, Server &server)
: client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this)),

View File

@ -1,19 +1,18 @@
#pragma once
// #include "webserv/http/HttpResponse.hpp"
#include "webserv/http/HttpResponse.hpp"
// #include <webserv/http/HttpResponse.hpp>
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/http/HttpConstants.hpp> // for OK
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <webserv/server/Server.hpp>
#include <webserv/socket/Socket.hpp>
#include <webserv/socket/Socket.hpp> // for Socket
#include <cstddef> // for size_t
#include <cstdint>
#include <cstdint> // for uint8_t
#include <memory> // for unique_ptr
#include <vector>
#include <vector> // for vector
class Server;
class Socket;
@ -39,6 +38,7 @@ class Client
[[nodiscard]] int getStatusCode() const;
[[nodiscard]] Socket &getSocket() const { return *client_socket_; }
// void setError(int statusCode);
void setStatusCode(int code);

View File

@ -1,11 +1,13 @@
#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
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/utils.hpp> // for trim
#include <sstream> // for basic_stringstream, stringstream
#include <utility> // for move, pair
#include <utility> // for pair, move
AConfig::AConfig(const AConfig *parent) : parent_(parent) {}

View File

@ -4,7 +4,7 @@
#include <webserv/config/directive/DirectiveValue.hpp>
#include <memory> // for unique_ptr
#include <optional>
#include <optional> // for nullopt, optional
#include <string> // for string
#include <vector> // for vector
@ -28,8 +28,7 @@ class AConfig
[[nodiscard]] const ADirective *getDirective(const std::string &name) const;
[[nodiscard]] std::vector<const ADirective *> getDirectives() const;
template <typename T>
std::optional<T> get(const std::string &name) const
template <typename T> std::optional<T> get(const std::string &name) const
{
const auto *directive = getDirective(name);
if (!directive)

View File

@ -1,9 +1,11 @@
#include <webserv/config/ConfigManager.hpp>
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
#include <webserv/log/Log.hpp> // for Log
#include <webserv/utils/utils.hpp> // for removeComments
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
#include <optional> // for optional
#include <sstream> // for basic_stringstream
#include <stdexcept> // for runtime_error
#include <string> // for basic_string, char_traits, operator+, string, to_string, operator==, stoi

View File

@ -1,4 +1,5 @@
#include <webserv/config/GlobalConfig.hpp>
#include <webserv/log/Log.hpp> // for Log
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace

View File

@ -1,5 +1,6 @@
#include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/log/Log.hpp> // for Log, LOCATION
LocationConfig::LocationConfig(const std::string &block, const std::string &path, const AConfig *parent)

View File

@ -19,6 +19,7 @@ class LocationConfig : public AConfig
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::string getType() const override;
[[nodiscard]] const std::string &getPath() const { return _path; }
private:

View File

@ -1,9 +1,11 @@
#include <webserv/config/ServerConfig.hpp>
#include <webserv/config/AConfig.hpp> // for AConfig
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp>
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace, trim
#include <optional> // for optional
#include <stdexcept> // for runtime_error
#include <utility> // for pair
@ -79,4 +81,3 @@ std::vector<std::string> ServerConfig::getLocationPaths() const
}
return paths;
}

View File

@ -27,7 +27,6 @@ class ServerConfig : public AConfig
[[nodiscard]] const LocationConfig *getLocation(const std::string &path) const;
[[nodiscard]] std::vector<std::string> getLocationPaths() const;
private:
std::map<std::string, std::unique_ptr<LocationConfig>> locations_;
AConfig *parent_ = nullptr;

View File

@ -1,18 +0,0 @@
#pragma once
#include "webserv/config/config_validator/AValidationRule.hpp"
#include "webserv/config/config_validator/ValidationResult.hpp"
#include <string>
#include <vector>
class AConfig;
class AllowedValuesRule : public AValidationRule
{
public:
explicit AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue = true);
private:
[[nodiscard]] ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const override;
std::vector<std::string> allowedValues_;
};

View File

@ -1,38 +0,0 @@
#include "webserv/config/config_validator/ConfigValidator.hpp"
#include "webserv/config/GlobalConfig.hpp"
#include "webserv/config/config_validator/AllowedValuesRule.hpp"
#include "webserv/config/config_validator/PortValidationRule.hpp"
#include "webserv/log/Log.hpp"
#include <string>
ConfigValidator::ConfigValidator(const GlobalConfig *config)
: engine_(std::make_unique<ValidationEngine>(config))
{
Log::trace(LOCATION);
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
engine_->addLocationRule("allowed_methods", std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
engine_->validate();
}
std::vector<ValidationResult> ConfigValidator::getValidationResults() const
{
return engine_->getValidationResults();
}
std::vector<ValidationResult> ConfigValidator::getErrors() const
{
return engine_->getErrors();
}
std::vector<ValidationResult> ConfigValidator::getWarnings() const
{
return engine_->getWarnings();
}
bool ConfigValidator::hasErrors() const
{
return engine_->hasErrors();
}

View File

@ -1,32 +0,0 @@
#include "webserv/config/config_validator/PortValidationRule.hpp"
#include "webserv/config/AConfig.hpp"
#include "webserv/config/config_validator/ValidationResult.hpp"
#include "webserv/config/directive/ADirective.hpp"
#include "webserv/config/directive/DirectiveValue.hpp"
#include "webserv/log/Log.hpp"
#include <string> // for string, basic_string, operator+, char_traits
PortValidationRule::PortValidationRule(bool requiresValue)
: AValidationRule("PortValidationRule", "Validates that the port number is within the valid range (1-65535)", requiresValue)
{
}
ValidationResult PortValidationRule::validateValue(const AConfig *config, const std::string &directiveName) const
{
Log::trace(LOCATION);
const ADirective *directive = config->getDirective(directiveName);
if (!directive->getValue().holds<int>())
{
return ValidationResult::error("Directive '" + directive->getName() + "' does not hold an integer value");
}
int port = directive->getValue().get<int>();
if (port < 1 || port > 65535)
{
return ValidationResult::error("Port number " + std::to_string(port) + " is out of valid range (1-65535)");
}
return ValidationResult::success();
}

View File

@ -1,14 +0,0 @@
#pragma once
#include "webserv/config/config_validator/AValidationRule.hpp"
#include <string>
class AConfig;
class PortValidationRule : public AValidationRule
{
public:
PortValidationRule(bool requiresValue = true);
private:
[[nodiscard]] ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const override;
};

View File

@ -1,14 +0,0 @@
#include "webserv/config/config_validator/ValidationResult.hpp"
#include "webserv/config/config_validator/RequiredDirectiveRule.hpp"
#include <webserv/config/config_validator/AValidationRule.hpp>
#include <webserv/config/AConfig.hpp>
RequiredDirectiveRule::RequiredDirectiveRule()
: AValidationRule("RequiredDirectiveRule", "Ensures that a required directive is present in the configuration", true)
{
}
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
{
return ValidationResult::success();
}

View File

@ -1,5 +1,6 @@
#include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/directive/BoolDirective.hpp> // for IntDirective
#include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
#include <webserv/utils/utils.hpp> // for trim

View File

@ -1,5 +1,6 @@
#include <webserv/config/directive/BoolDirective.hpp> // for BoolDirective
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
#include <webserv/config/directive/BoolDirective.hpp> // for BoolDirective
#include <webserv/config/directive/IntDirective.hpp> // for IntDirective
#include <webserv/config/directive/IntStringDirective.hpp> // for IntStringDirective
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective

View File

@ -1,6 +1,7 @@
#include <webserv/config/directive/IntStringDirective.hpp> // for IntDirective
#include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
#include <webserv/config/directive/IntStringDirective.hpp> // for IntDirective
#include <webserv/utils/utils.hpp> // for trim
#include <sstream> // for basic_istringstream, basic_istream::operator>>, istringstream

View File

@ -1,6 +1,7 @@
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
#include <webserv/config/directive/ADirective.hpp> // for ADirective
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
#include <webserv/utils/utils.hpp> // for trim
#include <algorithm> // for __transform_fn, transform

View File

@ -0,0 +1,45 @@
#include <webserv/config/validation/ConfigValidator.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/PortValidationRule.hpp> // for PortValidationRule
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <string> // for basic_string, string
ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make_unique<ValidationEngine>(config))
{
Log::trace(LOCATION);
/*Global Directive Rules*/
/*Server Directive Rules*/
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
/*Location Directive Rules*/
engine_->addLocationRule("allowed_methods",
std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
engine_->validate();
}
std::vector<ValidationResult> ConfigValidator::getValidationResults() const
{
return engine_->getValidationResults();
}
std::vector<ValidationResult> ConfigValidator::getErrors() const
{
return engine_->getErrors();
}
std::vector<ValidationResult> ConfigValidator::getWarnings() const
{
return engine_->getWarnings();
}
bool ConfigValidator::hasErrors() const
{
return engine_->hasErrors();
}

View File

@ -1,9 +1,13 @@
#pragma once
#include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <memory> // for unique_ptr
#include <vector> // for vector
#include "webserv/config/config_validator/ValidationEngine.hpp"
#include <memory>
class GlobalConfig;
class ConfigValidator
{
public:
@ -22,5 +26,4 @@ class ConfigValidator
private:
std::unique_ptr<ValidationEngine> engine_;
};

View File

@ -1,11 +1,14 @@
#include "webserv/config/config_validator/ValidationEngine.hpp"
#include <webserv/config/validation/ValidationEngine.hpp>
#include "webserv/config/AConfig.hpp"
#include "webserv/config/LocationConfig.hpp"
#include "webserv/config/config_validator/AValidationRule.hpp"
#include "webserv/config/config_validator/ValidationResult.hpp"
#include "webserv/config/directive/ADirective.hpp"
#include "webserv/log/Log.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/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <utility> // for move, get
void ValidationEngine::addGlobalRule(const std::string &directiveName, std::unique_ptr<AValidationRule> rule)
{

View File

@ -1,15 +1,21 @@
#pragma once
#include "webserv/config/GlobalConfig.hpp"
#include "webserv/config/config_validator/AValidationRule.hpp"
#include "webserv/config/config_validator/ValidationResult.hpp"
#include "webserv/config/LocationConfig.hpp"
#include "webserv/config/ServerConfig.hpp"
#include "webserv/config/AConfig.hpp"
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <webserv/config/AConfig.hpp>
#include <webserv/config/GlobalConfig.hpp>
#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/ServerConfig.hpp>
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <map> // for map
#include <memory> // for unique_ptr
#include <string> // for basic_string, string, operator<=>
#include <vector> // for vector
class AConfig;
class GlobalConfig;
class LocationConfig;
class ServerConfig;
class ValidationEngine
{

View File

@ -1,5 +1,8 @@
#include <webserv/config/config_validator/ValidationResult.hpp>
#include <webserv/log/Log.hpp>
#include <webserv/config/validation/ValidationResult.hpp>
#include <webserv/log/Log.hpp> // for Log
#include <utility> // for move
ValidationResult::ValidationResult(Type type, std::string message) : type_(type), message_(std::move(message)) {}

View File

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <cstdint>
#include <string>
class ValidationResult
{

View File

@ -1,8 +1,10 @@
#include <webserv/config/AConfig.hpp>
#include <webserv/config/config_validator/AValidationRule.hpp>
#include <webserv/config/config_validator/ValidationResult.hpp>
#include <webserv/config/directive/ADirective.hpp>
#include <webserv/log/Log.hpp>
#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/log/Log.hpp> // for LOCATION, Log
#include <utility> // for move
AValidationRule::AValidationRule(std::string ruleName, std::string description, bool requiresValue)
: ruleName_(std::move(ruleName)), description_(std::move(description)), requiresValue_(requiresValue)

View File

@ -1,6 +1,5 @@
#pragma once
#include <string>
#include <string> // for string, basic_string
class ValidationResult;
class ADirective;
@ -18,7 +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;

View File

@ -1,11 +1,15 @@
#include <webserv/config/AConfig.hpp>
#include <webserv/config/config_validator/AllowedValuesRule.hpp>
#include <webserv/config/config_validator/ValidationResult.hpp>
#include <webserv/config/directive/ADirective.hpp>
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp>
#include <algorithm> // for find
#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 <string> // for string, basic_string, operator+, char_traits
#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
AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue)

View File

@ -0,0 +1,20 @@
#pragma once
#include <webserv/config/validation/ValidationResult.hpp>
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <string> // for basic_string, string
#include <vector> // for vector
class AConfig;
class AllowedValuesRule : public AValidationRule
{
public:
explicit AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue = true);
private:
[[nodiscard]] ValidationResult validateValue(const AConfig *config,
const std::string &directiveName) const override;
std::vector<std::string> allowedValues_;
};

View File

@ -0,0 +1,34 @@
#include <webserv/config/validation/directive_rules/PortValidationRule.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 LOCATION, Log
#include <string> // for operator+, basic_string, allocator, char_traits, to_string, string
PortValidationRule::PortValidationRule(bool requiresValue)
: AValidationRule("PortValidationRule", "Validates that the port number is within the valid range (1-65535)",
requiresValue)
{
}
ValidationResult PortValidationRule::validateValue(const AConfig *config, const std::string &directiveName) const
{
Log::trace(LOCATION);
const ADirective *directive = config->getDirective(directiveName);
if (!directive->getValue().holds<int>())
{
return ValidationResult::error("Directive '" + directive->getName() + "' does not hold an integer value");
}
int port = directive->getValue().get<int>();
if (port < 1 || port > 65535)
{
return ValidationResult::error("Port number " + std::to_string(port) + " is out of valid range (1-65535)");
}
return ValidationResult::success();
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <string> // for string
class AConfig;
class PortValidationRule : public AValidationRule
{
public:
PortValidationRule(bool requiresValue = true);
private:
[[nodiscard]] ValidationResult validateValue(const AConfig *config,
const std::string &directiveName) const override;
};

View File

@ -0,0 +1,15 @@
#include <webserv/config/validation/directive_rules/RequiredDirectiveRule.hpp>
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
RequiredDirectiveRule::RequiredDirectiveRule()
: AValidationRule("RequiredDirectiveRule", "Ensures that a required directive is present in the configuration",
true)
{
}
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
{
return ValidationResult::success();
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "webserv/config/config_validator/AValidationRule.hpp"
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
#include <string>
#include <string> // for string
class AConfig;

View File

@ -1,8 +1,8 @@
#pragma once
#include "webserv/http/HttpResponse.hpp"
#include <webserv/config/AConfig.hpp>
#include <webserv/http/HttpResponse.hpp>
#include <memory>
class ErrorHandler

View File

@ -1,10 +1,9 @@
#include "webserv/http/HttpResponse.hpp"
#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 <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream

View File

@ -1,20 +1,21 @@
#include "webserv/handler/ErrorHandler.hpp"
#include "webserv/http/HttpConstants.hpp"
#include "webserv/http/HttpResponse.hpp"
#include <webserv/config/LocationConfig.hpp>
#include <webserv/handler/FileHandler.hpp>
#include <webserv/handler/MIMETypes.hpp>
#include <webserv/handler/URIParser.hpp>
#include <webserv/log/Log.hpp>
#include <webserv/utils/FileUtils.hpp>
#include <algorithm>
#include <cerrno> // for errno
#include <cstring> // for strerror, strlen
#include <memory>
#include <string>
#include <vector>
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/MIMETypes.hpp> // for MIMETypes
#include <webserv/handler/URIParser.hpp> // for URIParser
#include <webserv/http/HttpConstants.hpp> // for NOT_FOUND, FORBIDDEN, OK
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isFile, readBinaryFile
#include <functional> // for identity
#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 <utility> // for move
#include <vector> // for vector
FileHandler::FileHandler(const LocationConfig *location, const URIParser &uriParser)
: location_(location), uriParser_(uriParser)

View File

@ -1,12 +1,15 @@
#pragma once
#include "webserv/config/LocationConfig.hpp"
#include "webserv/handler/URIParser.hpp"
#include "webserv/http/HttpResponse.hpp"
#include <webserv/config/LocationConfig.hpp>
#include <webserv/handler/URIParser.hpp>
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <cstdint>
#include <memory>
#include <string>
#include <cstdint> // for uint8_t
#include <memory> // for unique_ptr
#include <string> // for string
class LocationConfig;
class URIParser;
class FileHandler
{

View File

@ -1,25 +1,30 @@
#include <webserv/handler/MIMETypes.hpp>
#include <utility> // for pair
MIMETypes::MIMETypes() {
MIMETypes::MIMETypes()
{
initializeDefaults();
}
std::string MIMETypes::getType(const std::string& extension) const {
std::string MIMETypes::getType(const std::string &extension) const
{
auto it = mimeMap.find(extension);
if (it != mimeMap.end()) {
if (it != mimeMap.end())
{
return it->second;
}
return "application/octet-stream"; // Default MIME type
}
void MIMETypes::setType(const std::string& extension, const std::string& mimeType) {
void MIMETypes::setType(const std::string &extension, const std::string &mimeType)
{
mimeMap[extension] = mimeType;
}
void MIMETypes::initializeDefaults() {
void MIMETypes::initializeDefaults()
{
mimeMap["html"] = "text/html";
mimeMap["htm"] = "text/html";
mimeMap["css"] = "text/css";

View File

@ -1,14 +1,14 @@
#ifndef MIMETYPES_HPP
#define MIMETYPES_HPP
#include <string>
#include <map>
#include <string>
class MIMETypes {
class MIMETypes
{
public:
MIMETypes();
// Returns the MIME type for a given file extension (e.g., "html" -> "text/html")
[[nodiscard]] std::string getType(const std::string &extension) const;

View File

@ -1,8 +1,13 @@
#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/ServerConfig.hpp>
#include <webserv/handler/URIParser.hpp>
#include <sys/stat.h> // for stat, S_ISREG, S_ISDIR
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <optional> // for optional
#include <vector> // for vector
#include <stddef.h> // for size_t
#include <sys/stat.h> // for stat, S_ISDIR, S_ISREG
URIParser::URIParser(const std::string &uri, const ServerConfig &serverConfig) : _locationConfig(nullptr)
{
@ -60,7 +65,6 @@ std::string URIParser::getExtension() const
return filename.substr(lastDot + 1);
}
LocationConfig const *URIParser::getLocation() const
{
return _locationConfig;
@ -91,4 +95,3 @@ bool URIParser::isValid() const
struct stat pathStat{};
return stat(getFilePath().c_str(), &pathStat) == 0;
}

View File

@ -1,20 +1,23 @@
#pragma once
#include "webserv/config/LocationConfig.hpp"
#include "webserv/config/ServerConfig.hpp"
#include "webserv/server/Server.hpp"
#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/ServerConfig.hpp>
#include <webserv/server/Server.hpp>
#include <string> // for string, basic_string
class LocationConfig;
class ServerConfig;
class URIParser
{
public:
URIParser(const std::string &uri, const ServerConfig &serverConfig);
[[nodiscard]] std::string getFilePath() const;
[[nodiscard]] std::string getFilename() const;
[[nodiscard]] std::string getExtension() const;
[[nodiscard]] const LocationConfig *getLocation() const;
[[nodiscard]] bool isFile() const;

View File

@ -1,4 +1,4 @@
#include "HttpConstants.hpp"
#include <webserv/http/HttpConstants.hpp>
#include <string>

View File

@ -1,8 +1,11 @@
#pragma once
#include <array>
#include <cstdint>
#include <string_view>
#include <array> // for array
#include <cstdint> // for uint16_t
#include <string> // for string
#include <string_view> // for string_view
#include <stddef.h> // for size_t
namespace Http
{

View File

@ -1,5 +1,6 @@
#include <webserv/http/HttpConstants.hpp> // for CRLF
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/http/HttpConstants.hpp> // for CRLF
#include <webserv/log/Log.hpp>
#include <webserv/utils/utils.hpp> // for trim

View File

@ -1,6 +1,7 @@
#include <webserv/http/HttpRequest.hpp>
#include <webserv/client/Client.hpp> // for Client
#include <webserv/http/HttpConstants.hpp> // for CRLF, DOUBLE_CRLF, BAD_REQUEST
#include <webserv/http/HttpRequest.hpp>
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/utils/utils.hpp> // for stoul

View File

@ -1,7 +1,7 @@
#include "webserv/http/HttpConstants.hpp"
#include <webserv/http/HttpResponse.hpp>
#include <webserv/http/HttpConstants.hpp>
#include <string>
#include <vector>

View File

@ -1,12 +1,12 @@
#pragma once
#include "webserv/http/HttpHeaders.hpp"
#include "webserv/log/Log.hpp"
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <cstdint> // for uint8_t
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
class Client;

View File

@ -1,10 +1,12 @@
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/config/validation/ConfigValidator.hpp> // for ConfigValidator
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
#include <webserv/log/Log.hpp> // for Log
#include <webserv/server/Server.hpp> // for Server
#include <webserv/config/config_validator/ConfigValidator.hpp> // for ConfigValidator
#include <iostream> // for basic_ostream, operator<<, cerr, ios_base
#include <string> // for basic_string, char_traits, allocator, operator+, operator<=>
#include <iostream> // for ios_base
#include <string> // for allocator, basic_string, char_traits, operator+, string
#include <vector> // for vector
int main(int argc, char **argv)
{

View File

@ -1,16 +1,18 @@
#include "webserv/config/AConfig.hpp"
#include "webserv/config/ConfigManager.hpp"
#include "webserv/config/ServerConfig.hpp"
#include "webserv/handler/ErrorHandler.hpp"
#include "webserv/handler/FileHandler.hpp"
#include "webserv/handler/URIParser.hpp"
#include "webserv/http/HttpResponse.hpp"
#include "webserv/log/Log.hpp"
#include <webserv/router/Router.hpp>
#include <memory>
#include <string>
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
#include <webserv/handler/FileHandler.hpp> // for FileHandler
#include <webserv/handler/URIParser.hpp> // for URIParser
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp> // for LOCATION, Log
#include <memory> // for unique_ptr
#include <optional> // for optional
#include <string> // for basic_string, string
class LocationConfig;
Router::Router() {}

View File

@ -1,12 +1,14 @@
#pragma once
#include "webserv/config/LocationConfig.hpp"
#include <webserv/config/LocationConfig.hpp>
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
#include <webserv/http/HttpRequest.hpp>
#include <webserv/http/HttpResponse.hpp>
#include <memory> // for unique_ptr
#include <string> // for string
#include <memory>
#include <string>
class LocationConfig;
class ServerConfig;
class Router
{

View File

@ -1,17 +1,19 @@
#include <webserv/server/Server.hpp>
#include <webserv/client/Client.hpp> // for Client
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/log/Log.hpp> // for Log
#include <webserv/server/Server.hpp>
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/socket/Socket.hpp> // for Socket
#include <cerrno> // for errno
#include <cstring> // for strerror, strlen
#include <cstring> // for strerror
#include <exception> // for exception
#include <memory> // for unique_ptr, allocator, make_unique
#include <optional> // for optional
#include <stdexcept> // for runtime_error
#include <string> // for basic_string, operator+, to_string, char_traits, string
#include <unordered_map> // for unordered_map, unordered_map<>::container_type
#include <unordered_map> // for unordered_map, operator==
#include <utility> // for move, pair
#include <vector> // for vector
@ -20,6 +22,8 @@
#include <sys/types.h> // for ssize_t
#include <unistd.h> // for close
class Router;
Server::Server(const ConfigManager &configManager)
: epoll_fd_(epoll_create1(0)), configManager_(configManager), router_()
{

View File

@ -1,10 +1,9 @@
#pragma once
#include "webserv/router/Router.hpp"
#include <webserv/client/Client.hpp>
#include <webserv/config/ConfigManager.hpp>
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/router/Router.hpp> // for Router
#include <webserv/socket/Socket.hpp> // for Socket
#include <cstdint> // for uint32_t

View File

@ -1,12 +1,13 @@
#include "webserv/log/Log.hpp"
#include <webserv/utils/FileUtils.hpp>
#include <cstring> // for strlen
#include <fstream>
#include <string> // for string
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <sys/stat.h> // for stat, S_ISREG, S_ISDIR
#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==
#include <string> // for basic_string, string, char_traits, operator+
#include <sys/stat.h> // for stat, S_ISDIR, S_ISREG
namespace FileUtils
{