refactor: add noexcept annotations to getters and observers
This commit is contained in:
parent
5efc48ff74
commit
67ab96f9da
@ -35,7 +35,7 @@ Client::~Client()
|
||||
server_.remove(*clientSocket_);
|
||||
};
|
||||
|
||||
int Client::getStatusCode() const
|
||||
int Client::getStatusCode() const noexcept
|
||||
{
|
||||
return statusCode_;
|
||||
}
|
||||
@ -210,12 +210,12 @@ void Client::respond() const
|
||||
server_.disconnect(*this); // ! CRITICAL: RETURN IMMEDIATELY
|
||||
}
|
||||
|
||||
HttpRequest &Client::getHttpRequest() const
|
||||
HttpRequest &Client::getHttpRequest() const noexcept
|
||||
{
|
||||
return *httpRequest_;
|
||||
}
|
||||
|
||||
HttpResponse &Client::getHttpResponse() const
|
||||
HttpResponse &Client::getHttpResponse() const noexcept
|
||||
{
|
||||
return *httpResponse_;
|
||||
}
|
||||
@ -40,15 +40,15 @@ class Client
|
||||
|
||||
void poll() const;
|
||||
|
||||
[[nodiscard]] int getStatusCode() const;
|
||||
[[nodiscard]] int getStatusCode() const noexcept;
|
||||
|
||||
[[nodiscard]] ASocket &getSocket(int fd = -1) const;
|
||||
|
||||
void setStatusCode(int code);
|
||||
void setCgiSockets(std::unique_ptr<CgiSocket> cgiStdIn, std::unique_ptr<CgiSocket> cgiStdOut);
|
||||
|
||||
[[nodiscard]] HttpRequest &getHttpRequest() const;
|
||||
[[nodiscard]] HttpResponse &getHttpResponse() const;
|
||||
[[nodiscard]] HttpRequest &getHttpRequest() const noexcept;
|
||||
[[nodiscard]] HttpResponse &getHttpResponse() const noexcept;
|
||||
|
||||
private:
|
||||
int statusCode_ = Http::StatusCode::OK;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#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
|
||||
|
||||
@ -20,7 +20,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; }
|
||||
[[nodiscard]] const std::string &getPath() const noexcept { return _path; }
|
||||
|
||||
private:
|
||||
void parseBlock(const std::string &block) override;
|
||||
|
||||
@ -41,7 +41,7 @@ class DirectiveValue
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] bool holds() const { return std::holds_alternative<T>(value_); }
|
||||
template <typename T> [[nodiscard]] bool holds() const noexcept { return std::holds_alternative<T>(value_); }
|
||||
|
||||
[[nodiscard]] std::string toString() const;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#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
|
||||
@ -60,7 +59,7 @@ std::vector<ValidationResult> ConfigValidator::getWarnings() const
|
||||
return engine_->getWarnings();
|
||||
}
|
||||
|
||||
bool ConfigValidator::hasErrors() const
|
||||
bool ConfigValidator::hasErrors() const noexcept
|
||||
{
|
||||
return engine_->hasErrors();
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class ConfigValidator
|
||||
[[nodiscard]] std::vector<ValidationResult> getValidationResults() const;
|
||||
[[nodiscard]] std::vector<ValidationResult> getErrors() const;
|
||||
[[nodiscard]] std::vector<ValidationResult> getWarnings() const;
|
||||
[[nodiscard]] bool hasErrors() const;
|
||||
[[nodiscard]] bool hasErrors() const noexcept;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ValidationEngine> engine_;
|
||||
|
||||
@ -71,7 +71,7 @@ std::vector<ValidationResult> ValidationEngine::getWarnings() const
|
||||
return warnings;
|
||||
}
|
||||
|
||||
bool ValidationEngine::hasErrors() const
|
||||
bool ValidationEngine::hasErrors() const noexcept
|
||||
{
|
||||
for (const auto &result : results_) // NOLINT(readability-use-anyofallof)
|
||||
{
|
||||
|
||||
@ -42,7 +42,7 @@ class ValidationEngine
|
||||
[[nodiscard]] std::vector<ValidationResult> getValidationResults() const;
|
||||
[[nodiscard]] std::vector<ValidationResult> getErrors() const;
|
||||
[[nodiscard]] std::vector<ValidationResult> getWarnings() const;
|
||||
[[nodiscard]] bool hasErrors() const;
|
||||
[[nodiscard]] bool hasErrors() const noexcept;
|
||||
|
||||
private:
|
||||
static void addRule(RuleMap &ruleMap, const std::string &directiveName, std::unique_ptr<AValidationRule> rule);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include <webserv/config/validation/ValidationResult.hpp>
|
||||
|
||||
#include <webserv/log/Log.hpp> // for Log
|
||||
|
||||
#include <utility> // for move
|
||||
@ -23,12 +22,12 @@ ValidationResult ValidationResult::warning(const std::string &message)
|
||||
return {ValidationResult::Type::WARNING, message};
|
||||
}
|
||||
|
||||
bool ValidationResult::isValidResult() const
|
||||
bool ValidationResult::isValidResult() const noexcept
|
||||
{
|
||||
return type_ == Type::SUCCESS;
|
||||
}
|
||||
|
||||
ValidationResult::Type ValidationResult::getType() const
|
||||
ValidationResult::Type ValidationResult::getType() const noexcept
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
@ -24,8 +24,8 @@ class ValidationResult
|
||||
static ValidationResult error(const std::string &message);
|
||||
static ValidationResult warning(const std::string &message);
|
||||
|
||||
[[nodiscard]] bool isValidResult() const;
|
||||
[[nodiscard]] ValidationResult::Type getType() const;
|
||||
[[nodiscard]] bool isValidResult() const noexcept;
|
||||
[[nodiscard]] ValidationResult::Type getType() const noexcept;
|
||||
[[nodiscard]] std::string getMessage() const;
|
||||
|
||||
private:
|
||||
|
||||
@ -149,14 +149,15 @@ bool URI::isValid() const noexcept
|
||||
return FileUtils::isValidPath(fullPath_);
|
||||
}
|
||||
|
||||
bool URI::isCgi() const
|
||||
bool URI::isCgi() const noexcept
|
||||
{
|
||||
return !getCgiPath().empty();
|
||||
}
|
||||
|
||||
std::string URI::getCgiPath() const
|
||||
{
|
||||
// Log::debug("BaseName: " + baseName_ + ", FullPath: " + fullPath_ + ", Dir: " + dir_ + ", PathInfo: " + pathInfo_ +
|
||||
// Log::debug("BaseName: " + baseName_ + ", FullPath: " + fullPath_ + ", Dir: " + dir_ + ", PathInfo: " + pathInfo_
|
||||
// +
|
||||
// ", Extension: " + getExtension());
|
||||
if (!isFile() || getExtension().empty() || !config_->get<bool>("cgi_enabled").has_value()
|
||||
|| !config_->get<bool>("cgi_enabled").value())
|
||||
|
||||
@ -23,7 +23,7 @@ class URI
|
||||
[[nodiscard]] bool isFile() const noexcept;
|
||||
[[nodiscard]] bool isDirectory() const noexcept;
|
||||
[[nodiscard]] bool isValid() const noexcept;
|
||||
[[nodiscard]] bool isCgi() const;
|
||||
[[nodiscard]] bool isCgi() const noexcept;
|
||||
|
||||
[[nodiscard]] std::string getExtension() const noexcept;
|
||||
[[nodiscard]] std::string getCgiPath() const;
|
||||
|
||||
@ -24,7 +24,7 @@ HttpRequest::~HttpRequest()
|
||||
Log::trace(LOCATION);
|
||||
}
|
||||
|
||||
HttpRequest::State HttpRequest::getState() const
|
||||
HttpRequest::State HttpRequest::getState() const noexcept
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
@ -39,12 +39,12 @@ void HttpRequest::setState(State state)
|
||||
state_ = state;
|
||||
}
|
||||
|
||||
const HttpHeaders &HttpRequest::getHeaders() const
|
||||
const HttpHeaders &HttpRequest::getHeaders() const noexcept
|
||||
{
|
||||
return headers_;
|
||||
}
|
||||
|
||||
const std::string &HttpRequest::getBody() const
|
||||
const std::string &HttpRequest::getBody() const noexcept
|
||||
{
|
||||
return body_;
|
||||
}
|
||||
@ -233,27 +233,27 @@ void HttpRequest::reset()
|
||||
// contentLength_ = 0;
|
||||
}
|
||||
|
||||
const URI &HttpRequest::getUri() const
|
||||
const URI &HttpRequest::getUri() const noexcept
|
||||
{
|
||||
return *uri_;
|
||||
}
|
||||
|
||||
const std::string &HttpRequest::getMethod() const
|
||||
const std::string &HttpRequest::getMethod() const noexcept
|
||||
{
|
||||
return method_;
|
||||
}
|
||||
|
||||
const std::string &HttpRequest::getTarget() const
|
||||
const std::string &HttpRequest::getTarget() const noexcept
|
||||
{
|
||||
return target_;
|
||||
}
|
||||
|
||||
const std::string &HttpRequest::getHttpVersion() const
|
||||
const std::string &HttpRequest::getHttpVersion() const noexcept
|
||||
{
|
||||
return httpVersion_;
|
||||
}
|
||||
|
||||
Client &HttpRequest::getClient() const
|
||||
Client &HttpRequest::getClient() const noexcept
|
||||
{
|
||||
return *client_;
|
||||
}
|
||||
|
||||
@ -33,14 +33,14 @@ class HttpRequest
|
||||
HttpRequest &operator=(HttpRequest &&other) noexcept = delete;
|
||||
~HttpRequest();
|
||||
|
||||
[[nodiscard]] State getState() const;
|
||||
[[nodiscard]] const URI &getUri() const;
|
||||
[[nodiscard]] const HttpHeaders &getHeaders() const;
|
||||
[[nodiscard]] const std::string &getBody() const;
|
||||
[[nodiscard]] const std::string &getMethod() const;
|
||||
[[nodiscard]] const std::string &getTarget() const;
|
||||
[[nodiscard]] const std::string &getHttpVersion() const;
|
||||
[[nodiscard]] Client &getClient() const;
|
||||
[[nodiscard]] State getState() const noexcept;
|
||||
[[nodiscard]] const URI &getUri() const noexcept;
|
||||
[[nodiscard]] const HttpHeaders &getHeaders() const noexcept;
|
||||
[[nodiscard]] const std::string &getBody() const noexcept;
|
||||
[[nodiscard]] const std::string &getMethod() const noexcept;
|
||||
[[nodiscard]] const std::string &getTarget() const noexcept;
|
||||
[[nodiscard]] const std::string &getHttpVersion() const noexcept;
|
||||
[[nodiscard]] Client &getClient() const noexcept;
|
||||
|
||||
void setState(State state);
|
||||
void receiveData(const char *data, size_t length);
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include <webserv/http/HttpResponse.hpp>
|
||||
|
||||
#include <webserv/http/HttpConstants.hpp> // for getStatusCodeReason
|
||||
#include <webserv/http/HttpResponse.hpp>
|
||||
|
||||
#include <string> // for basic_string, operator+, string, char_traits, to_string
|
||||
#include <vector> // for vector
|
||||
@ -44,12 +43,12 @@ void HttpResponse::setComplete()
|
||||
complete_ = true;
|
||||
}
|
||||
|
||||
bool HttpResponse::isComplete() const
|
||||
bool HttpResponse::isComplete() const noexcept
|
||||
{
|
||||
return complete_;
|
||||
}
|
||||
|
||||
const HttpHeaders &HttpResponse::getHeaders() const
|
||||
const HttpHeaders &HttpResponse::getHeaders() const noexcept
|
||||
{
|
||||
return *headers_;
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ class HttpResponse
|
||||
|
||||
void setStatus(uint16_t statusCode);
|
||||
|
||||
[[nodiscard]] bool isComplete() const;
|
||||
[[nodiscard]] bool isComplete() const noexcept;
|
||||
|
||||
[[nodiscard]] const HttpHeaders &getHeaders() const;
|
||||
[[nodiscard]] const HttpHeaders &getHeaders() const noexcept;
|
||||
|
||||
[[nodiscard]] std::vector<uint8_t> toBytes() const;
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ Router::Router(Client *client) : client_(client)
|
||||
Log::trace(LOCATION);
|
||||
}
|
||||
|
||||
bool Router::isMethodSupported(const std::string &method, const AConfig &config)
|
||||
bool Router::isMethodSupported(const std::string &method, const AConfig &config) noexcept
|
||||
{
|
||||
const ADirective *allowedMethods = config.getDirective("allowed_methods");
|
||||
if (allowedMethods == nullptr || !allowedMethods->getValue().try_get<std::vector<std::string>>().has_value())
|
||||
|
||||
@ -19,5 +19,5 @@ class Router
|
||||
|
||||
private:
|
||||
Client *client_;
|
||||
[[nodiscard]] bool isMethodSupported(const std::string &method, const AConfig &config);
|
||||
[[nodiscard]] bool isMethodSupported(const std::string &method, const AConfig &config) noexcept;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user