refactor: optimize compiler options and clean up unused directives
This commit is contained in:
parent
60dda17042
commit
7b6ce8fd67
@ -106,7 +106,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||||||
add_definitions(-DDEBUG)
|
add_definitions(-DDEBUG)
|
||||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
message(STATUS "Release build: adding optimization flags")
|
message(STATUS "Release build: adding optimization flags")
|
||||||
add_compile_options(-O3)
|
add_compile_options(-O2 -g -Wall -Wextra -Werror)
|
||||||
add_definitions(-DNDEBUG)
|
add_definitions(-DNDEBUG)
|
||||||
elseif(CMAKE_BUILD_TYPE STREQUAL "ASAN")
|
elseif(CMAKE_BUILD_TYPE STREQUAL "ASAN")
|
||||||
message(STATUS "AddressSanitizer build: adding sanitizer flags")
|
message(STATUS "AddressSanitizer build: adding sanitizer flags")
|
||||||
|
|||||||
@ -42,8 +42,8 @@ server {
|
|||||||
allowed_methods GET;
|
allowed_methods GET;
|
||||||
}
|
}
|
||||||
|
|
||||||
cgi_enabled yes;
|
# cgi_enabled yes;
|
||||||
cgi_ext .php /usr/bin/php-cgi;
|
# cgi_ext .php /usr/bin/php-cgi;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
@ -85,6 +85,6 @@ server {
|
|||||||
# allowed_methods GET;
|
# allowed_methods GET;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
cgi_enabled yes;
|
# cgi_enabled yes;
|
||||||
cgi_ext .php /usr/bin/php-cgi;
|
# cgi_ext .php /usr/bin/php-cgi;
|
||||||
}
|
}
|
||||||
@ -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)
|
||||||
: client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this)),
|
: httpRequest_(std::make_unique<HttpRequest>(this)), httpResponse_(std::make_unique<HttpResponse>()), client_socket_(std::move(socket)),
|
||||||
httpResponse_(std::make_unique<HttpResponse>())
|
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()));
|
||||||
@ -98,6 +98,7 @@ std::vector<uint8_t> Client::getResponse() const
|
|||||||
Log::trace(LOCATION);
|
Log::trace(LOCATION);
|
||||||
|
|
||||||
const Router &router = server_.getRouter();
|
const Router &router = server_.getRouter();
|
||||||
|
static_cast<void>(router); // Suppress unused variable warning
|
||||||
auto response = Router::handleRequest(*httpRequest_);
|
auto response = Router::handleRequest(*httpRequest_);
|
||||||
return response->toBytes();
|
return response->toBytes();
|
||||||
}
|
}
|
||||||
@ -50,5 +50,5 @@ class Client
|
|||||||
std::unique_ptr<HttpResponse> httpResponse_ = nullptr;
|
std::unique_ptr<HttpResponse> httpResponse_ = nullptr;
|
||||||
std::unique_ptr<Socket> client_socket_;
|
std::unique_ptr<Socket> client_socket_;
|
||||||
Server &server_;
|
Server &server_;
|
||||||
mutable const ServerConfig *server_config_ = nullptr;
|
// mutable const ServerConfig *server_config_ = nullptr;
|
||||||
};
|
};
|
||||||
@ -84,7 +84,7 @@ void AConfig::parseDirectives(const std::string &declarations)
|
|||||||
std::string AConfig::getErrorPage(int statusCode) const
|
std::string AConfig::getErrorPage(int statusCode) const
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
const ADirective *directive = getDirective("error_page");
|
Log::trace(LOCATION);
|
||||||
for (const auto &directive : directives_)
|
for (const auto &directive : directives_)
|
||||||
{
|
{
|
||||||
if (directive->getName() == "error_page")
|
if (directive->getName() == "error_page")
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class GlobalConfig : public AConfig
|
|||||||
[[nodiscard]] std::vector<ServerConfig *> getServerConfigs() const;
|
[[nodiscard]] std::vector<ServerConfig *> getServerConfigs() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AConfig *parent_ = nullptr;
|
// AConfig *parent_;
|
||||||
std::vector<std::unique_ptr<ServerConfig>> servers_;
|
std::vector<std::unique_ptr<ServerConfig>> servers_;
|
||||||
|
|
||||||
void parseBlock(const std::string &block) override;
|
void parseBlock(const std::string &block) override;
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class ServerConfig : public AConfig
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::unique_ptr<LocationConfig>> locations_;
|
std::map<std::string, std::unique_ptr<LocationConfig>> locations_;
|
||||||
AConfig *parent_ = nullptr;
|
// AConfig *parent_;
|
||||||
|
|
||||||
void parseBlock(const std::string &block) override;
|
void parseBlock(const std::string &block) override;
|
||||||
};
|
};
|
||||||
@ -27,13 +27,13 @@ ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make
|
|||||||
/*Server Directive Rules*/
|
/*Server Directive Rules*/
|
||||||
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
|
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
|
||||||
engine_->addServerRule("host", std::make_unique<HostValidationRule>());
|
engine_->addServerRule("host", std::make_unique<HostValidationRule>());
|
||||||
engine_->addServerRule("root", std::make_unique<FolderExistsRule>(true));
|
engine_->addServerRule("root", std::make_unique<FolderExistsRule>(false));
|
||||||
|
|
||||||
/*Location Directive Rules*/
|
/*Location Directive Rules*/
|
||||||
engine_->addLocationRule("allowed_methods",
|
engine_->addLocationRule("allowed_methods",
|
||||||
std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
|
std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
|
||||||
engine_->addLocationRule("root", std::make_unique<FolderExistsRule>(true));
|
engine_->addLocationRule("root", std::make_unique<FolderExistsRule>(true));
|
||||||
engine_->addLocationRule("cgi_ext", std::make_unique<CgiExtValidationRule>(true));
|
engine_->addLocationRule("cgi_ext", std::make_unique<CgiExtValidationRule>(false));
|
||||||
|
|
||||||
engine_->validate();
|
engine_->validate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,5 +11,7 @@ RequiredDirectiveRule::RequiredDirectiveRule()
|
|||||||
|
|
||||||
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
||||||
{
|
{
|
||||||
|
static_cast<void>(config); // Suppress unused parameter warning
|
||||||
|
static_cast<void>(directiveName);
|
||||||
return ValidationResult::success();
|
return ValidationResult::success();
|
||||||
}
|
}
|
||||||
@ -85,6 +85,7 @@ std::unique_ptr<HttpResponse> FileHandler::getResponse() const
|
|||||||
|
|
||||||
FileHandler::ResourceType FileHandler::getResourceType(const std::string &path) const
|
FileHandler::ResourceType FileHandler::getResourceType(const std::string &path) const
|
||||||
{
|
{
|
||||||
|
static_cast<void>(path);
|
||||||
Log::trace(LOCATION);
|
Log::trace(LOCATION);
|
||||||
|
|
||||||
if (uriParser_.isFile())
|
if (uriParser_.isFile())
|
||||||
|
|||||||
@ -45,6 +45,7 @@ std::unique_ptr<HttpResponse> Router::handleRequest(const HttpRequest &request)
|
|||||||
URIParser uriParser{request.getTarget(), *config};
|
URIParser uriParser{request.getTarget(), *config};
|
||||||
|
|
||||||
const std::string &target = request.getTarget();
|
const std::string &target = request.getTarget();
|
||||||
|
static_cast<void>(target); // Suppress unused variable warning
|
||||||
const std::string &method = request.getMethod();
|
const std::string &method = request.getMethod();
|
||||||
|
|
||||||
const LocationConfig *location = uriParser.getLocation();
|
const LocationConfig *location = uriParser.getLocation();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user