more no except and const

This commit is contained in:
whaffman 2025-10-16 00:38:55 +02:00
parent 7432cd154c
commit 259d7f1371
17 changed files with 62 additions and 62 deletions

View File

@ -52,7 +52,7 @@ class Client
private: private:
int statusCode_ = Http::StatusCode::OK; int statusCode_ = Http::StatusCode::OK;
constexpr static size_t bufferSize_ = 8192 * 300; // 8KB buffer for reading CGI output constexpr static size_t bufferSize_ = 8192; // 8KB buffer for reading CGI output
std::unique_ptr<HttpRequest> httpRequest_; std::unique_ptr<HttpRequest> httpRequest_;
std::unique_ptr<HttpResponse> httpResponse_; std::unique_ptr<HttpResponse> httpResponse_;
std::unique_ptr<Router> router_; std::unique_ptr<Router> router_;

View File

@ -129,22 +129,22 @@ std::map<std::string, std::string> URI::getCGIEnvironment() const
return env; return env;
} }
const AConfig *URI::getConfig() const const AConfig *URI::getConfig() const noexcept
{ {
return config_; return config_;
} }
bool URI::isFile() const bool URI::isFile() const noexcept
{ {
return !baseName_.empty(); return !baseName_.empty();
} }
bool URI::isDirectory() const bool URI::isDirectory() const noexcept
{ {
return baseName_.empty(); return baseName_.empty();
} }
bool URI::isValid() const bool URI::isValid() const noexcept
{ {
return FileUtils::isValidPath(fullPath_); return FileUtils::isValidPath(fullPath_);
} }
@ -172,42 +172,42 @@ std::string URI::getCgiPath() const
return cgiPath; return cgiPath;
} }
const std::string &URI::getBaseName() const const std::string &URI::getBaseName() const noexcept
{ {
return baseName_; return baseName_;
} }
std::string URI::getExtension() const std::string URI::getExtension() const noexcept
{ {
return FileUtils::getExtension(baseName_); return FileUtils::getExtension(baseName_);
} }
const std::string &URI::getFullPath() const const std::string &URI::getFullPath() const noexcept
{ {
return fullPath_; return fullPath_;
} }
const std::string &URI::getDir() const const std::string &URI::getDir() const noexcept
{ {
return dir_; return dir_;
} }
const std::string &URI::getPathInfo() const const std::string &URI::getPathInfo() const noexcept
{ {
return pathInfo_; return pathInfo_;
} }
const std::string &URI::getQuery() const const std::string &URI::getQuery() const noexcept
{ {
return query_; return query_;
} }
const std::string &URI::getFragment() const const std::string &URI::getFragment() const noexcept
{ {
return fragment_; return fragment_;
} }
const std::string &URI::getAuthority() const const std::string &URI::getAuthority() const noexcept
{ {
return authority_; return authority_;
} }

View File

@ -20,21 +20,21 @@ class URI
[[nodiscard]] std::map<std::string, std::string> getCGIEnvironment() const; [[nodiscard]] std::map<std::string, std::string> getCGIEnvironment() const;
[[nodiscard]] bool isFile() const; [[nodiscard]] bool isFile() const noexcept;
[[nodiscard]] bool isDirectory() const; [[nodiscard]] bool isDirectory() const noexcept;
[[nodiscard]] bool isValid() const; [[nodiscard]] bool isValid() const noexcept;
[[nodiscard]] bool isCgi() const; [[nodiscard]] bool isCgi() const;
[[nodiscard]] std::string getExtension() const; [[nodiscard]] std::string getExtension() const noexcept;
[[nodiscard]] std::string getCgiPath() const; [[nodiscard]] std::string getCgiPath() const;
[[nodiscard]] const AConfig *getConfig() const; [[nodiscard]] const AConfig *getConfig() const noexcept;
[[nodiscard]] const std::string &getBaseName() const; [[nodiscard]] const std::string &getBaseName() const noexcept;
[[nodiscard]] const std::string &getFullPath() const; [[nodiscard]] const std::string &getFullPath() const noexcept;
[[nodiscard]] const std::string &getDir() const; [[nodiscard]] const std::string &getDir() const noexcept;
[[nodiscard]] const std::string &getPathInfo() const; [[nodiscard]] const std::string &getPathInfo() const noexcept;
[[nodiscard]] const std::string &getQuery() const; [[nodiscard]] const std::string &getQuery() const noexcept;
[[nodiscard]] const std::string &getFragment() const; [[nodiscard]] const std::string &getFragment() const noexcept;
[[nodiscard]] const std::string &getAuthority() const; [[nodiscard]] const std::string &getAuthority() const noexcept;
private: private:
void parseUri(const std::string &uri); void parseUri(const std::string &uri);

View File

@ -4,7 +4,7 @@
namespace Http namespace Http
{ {
std::string getStatusCodeReason(uint16_t statusCode) std::string getStatusCodeReason(uint16_t statusCode) noexcept
{ {
for (const auto &info : statusCodeInfos) for (const auto &info : statusCodeInfos)
{ {

View File

@ -66,7 +66,7 @@ static constexpr std::array<StatusCodeInfo, 12> statusCodeInfos
{.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"}, {.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"},
{.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}}; {.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}};
std::string getStatusCodeReason(uint16_t statusCode); std::string getStatusCodeReason(uint16_t statusCode) noexcept;
// Header Names // Header Names
namespace Header namespace Header

View File

@ -7,7 +7,7 @@
#include <cctype> // for tolower #include <cctype> // for tolower
#include <utility> // for pair #include <utility> // for pair
std::optional<size_t> HttpHeaders::getContentLength() const std::optional<size_t> HttpHeaders::getContentLength() const noexcept
{ {
const auto &value = this->get("Content-Length"); const auto &value = this->get("Content-Length");
if (value.empty()) if (value.empty())
@ -17,7 +17,7 @@ std::optional<size_t> HttpHeaders::getContentLength() const
return utils::stoul(value); return utils::stoul(value);
} }
std::optional<std::string> HttpHeaders::getContentType() const std::optional<std::string> HttpHeaders::getContentType() const noexcept
{ {
const auto &value = this->get("Content-Type"); const auto &value = this->get("Content-Type");
if (value.empty()) if (value.empty())
@ -27,7 +27,7 @@ std::optional<std::string> HttpHeaders::getContentType() const
return value; return value;
} }
std::optional<std::string> HttpHeaders::getHost() const std::optional<std::string> HttpHeaders::getHost() const noexcept
{ {
const auto &value = this->get("Host"); const auto &value = this->get("Host");
if (value.empty()) if (value.empty())
@ -37,19 +37,19 @@ std::optional<std::string> HttpHeaders::getHost() const
return value; return value;
} }
void HttpHeaders::add(const std::string &name, const std::string &value) // NOLINT(bugprone-easily-swappable-parameters) void HttpHeaders::add(const std::string &name, const std::string &value) noexcept// NOLINT(bugprone-easily-swappable-parameters)
{ {
std::string lower = name; std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower); std::ranges::transform(lower, lower.begin(), ::tolower);
headers_[lower] = value; headers_[lower] = value;
} }
void HttpHeaders::remove(const std::string &name) void HttpHeaders::remove(const std::string &name) noexcept
{ {
headers_.erase(name); headers_.erase(name);
} }
const std::string &HttpHeaders::get(const std::string &name) const const std::string &HttpHeaders::get(const std::string &name) const noexcept
{ {
std::string lower = name; std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower); std::ranges::transform(lower, lower.begin(), ::tolower);
@ -62,14 +62,14 @@ const std::string &HttpHeaders::get(const std::string &name) const
return empty; return empty;
} }
bool HttpHeaders::has(const std::string &name) const bool HttpHeaders::has(const std::string &name) const noexcept
{ {
std::string lower = name; std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower); std::ranges::transform(lower, lower.begin(), ::tolower);
return headers_.contains(lower); return headers_.contains(lower);
} }
void HttpHeaders::parse(const std::string &rawHeaders) void HttpHeaders::parse(const std::string &rawHeaders) noexcept
{ {
Log::trace(LOCATION); Log::trace(LOCATION);
size_t start = 0; size_t start = 0;
@ -92,7 +92,7 @@ void HttpHeaders::parse(const std::string &rawHeaders)
} }
} }
std::string HttpHeaders::toString() const std::string HttpHeaders::toString() const noexcept
{ {
std::string result; std::string result;
for (const auto &pair : headers_) for (const auto &pair : headers_)

View File

@ -18,17 +18,17 @@
class HttpHeaders class HttpHeaders
{ {
public: public:
[[nodiscard]] const std::string &get(const std::string &name) const; [[nodiscard]] const std::string &get(const std::string &name) const noexcept;
[[nodiscard]] bool has(const std::string &name) const; [[nodiscard]] bool has(const std::string &name) const noexcept;
void parse(const std::string &rawHeaders); void parse(const std::string &rawHeaders) noexcept;
void add(const std::string &name, const std::string &value); void add(const std::string &name, const std::string &value) noexcept;
void remove(const std::string &name); void remove(const std::string &name) noexcept;
[[nodiscard]] std::string toString() const; [[nodiscard]] std::string toString() const noexcept;
[[nodiscard]] std::optional<size_t> getContentLength() const; [[nodiscard]] std::optional<size_t> getContentLength() const noexcept;
[[nodiscard]] std::optional<std::string> getContentType() const; [[nodiscard]] std::optional<std::string> getContentType() const noexcept;
[[nodiscard]] std::optional<std::string> getHost() const; [[nodiscard]] std::optional<std::string> getHost() const noexcept;
private: private:
std::unordered_map<std::string, std::string> headers_; std::unordered_map<std::string, std::string> headers_;

View File

@ -182,7 +182,7 @@ void Server::responseReady(int client_fd) const
} }
} }
void Server::handleResponse(struct epoll_event *event) void Server::handleResponse(struct epoll_event *event) const
{ {
int socket_fd = event->data.fd; int socket_fd = event->data.fd;
Log::debug("Attempting to send data to fd: " + std::to_string(socket_fd)); Log::debug("Attempting to send data to fd: " + std::to_string(socket_fd));
@ -191,7 +191,7 @@ void Server::handleResponse(struct epoll_event *event)
// disconnect(client); // disconnect(client);
} }
void Server::handleEpollHangUp(struct epoll_event *event) void Server::handleEpollHangUp(struct epoll_event *event) const
{ {
Client &client = getClient(event->data.fd); Client &client = getClient(event->data.fd);
ASocket &socket = client.getSocket(event->data.fd); ASocket &socket = client.getSocket(event->data.fd);

View File

@ -52,11 +52,11 @@ class Server
void pollClients() const; void pollClients() const;
void handleEpoll(struct epoll_event *events, int max_events); void handleEpoll(struct epoll_event *events, int max_events);
void handleEpollHangUp(struct epoll_event *event); void handleEpollHangUp(struct epoll_event *event) const;
void handleEvent(struct epoll_event *event); void handleEvent(struct epoll_event *event);
void handleConnection(struct epoll_event *event); void handleConnection(struct epoll_event *event);
void handleRequest(struct epoll_event *event) const; void handleRequest(struct epoll_event *event) const;
void handleResponse(struct epoll_event *event); void handleResponse(struct epoll_event *event) const;
void setupServerSocket(const ServerConfig &config); void setupServerSocket(const ServerConfig &config);
}; };

View File

@ -60,7 +60,7 @@ void ASocket::setNonBlocking() const
} }
} }
int ASocket::getFd() const int ASocket::getFd() const noexcept
{ {
return fd_; return fd_;
} }

View File

@ -26,8 +26,8 @@ class ASocket
virtual ~ASocket(); virtual ~ASocket();
[[nodiscard]] virtual Type getType() const = 0; [[nodiscard]] virtual Type getType() const noexcept = 0;
[[nodiscard]] int getFd() const; [[nodiscard]] int getFd() const noexcept;
void callback() const; void callback() const;
void setCallback(std::function<void()> callback); void setCallback(std::function<void()> callback);

View File

@ -8,7 +8,7 @@ CgiSocket::CgiSocket(int fd) : ASocket(fd)
Log::trace(LOCATION); Log::trace(LOCATION);
} }
ASocket::Type CgiSocket::getType() const ASocket::Type CgiSocket::getType() const noexcept
{ {
return ASocket::Type::CGI_SOCKET; return ASocket::Type::CGI_SOCKET;
} }

View File

@ -11,7 +11,7 @@ class CgiSocket : public ASocket
public: public:
explicit CgiSocket(int fd); explicit CgiSocket(int fd);
[[nodiscard]] ASocket::Type getType() const override; [[nodiscard]] ASocket::Type getType() const noexcept override;
ssize_t read(void *buf, size_t len) const override; ssize_t read(void *buf, size_t len) const override;
ssize_t write(const void *buf, size_t len) const override; ssize_t write(const void *buf, size_t len) const override;

View File

@ -7,7 +7,7 @@ ClientSocket::ClientSocket(int fd) : ASocket(fd)
Log::trace(LOCATION); Log::trace(LOCATION);
} }
ASocket::Type ClientSocket::getType() const ASocket::Type ClientSocket::getType() const noexcept
{ {
return ASocket::Type::CLIENT_SOCKET; return ASocket::Type::CLIENT_SOCKET;
} }

View File

@ -11,5 +11,5 @@ class ClientSocket : public ASocket
public: public:
explicit ClientSocket(int fd); explicit ClientSocket(int fd);
[[nodiscard]] ASocket::Type getType() const override; [[nodiscard]] ASocket::Type getType() const noexcept override;
}; };

View File

@ -62,7 +62,7 @@ void ServerSocket::bind(const std::string &host, const int port) const
} }
} }
ASocket::Type ServerSocket::getType() const ASocket::Type ServerSocket::getType() const noexcept
{ {
return ASocket::Type::SERVER_SOCKET; return ASocket::Type::SERVER_SOCKET;
} }

View File

@ -15,6 +15,6 @@ class ServerSocket : public ASocket
void listen(int backlog) const; void listen(int backlog) const;
void bind(const std::string &host, int port) const; void bind(const std::string &host, int port) const;
[[nodiscard]] ASocket::Type getType() const override; [[nodiscard]] ASocket::Type getType() const noexcept override;
[[nodiscard]] std::unique_ptr<ClientSocket> accept() const; [[nodiscard]] std::unique_ptr<ClientSocket> accept() const;
}; };