From 259d7f13714b173d55d8850a71a5953e3bab1db2 Mon Sep 17 00:00:00 2001 From: whaffman Date: Thu, 16 Oct 2025 00:38:55 +0200 Subject: [PATCH] more no except and const --- webserv/client/Client.hpp | 2 +- webserv/handler/URI.cpp | 24 ++++++++++++------------ webserv/handler/URI.hpp | 24 ++++++++++++------------ webserv/http/HttpConstants.cpp | 2 +- webserv/http/HttpConstants.hpp | 2 +- webserv/http/HttpHeaders.cpp | 18 +++++++++--------- webserv/http/HttpHeaders.hpp | 18 +++++++++--------- webserv/server/Server.cpp | 4 ++-- webserv/server/Server.hpp | 4 ++-- webserv/socket/ASocket.cpp | 2 +- webserv/socket/ASocket.hpp | 4 ++-- webserv/socket/CgiSocket.cpp | 6 +++--- webserv/socket/CgiSocket.hpp | 6 +++--- webserv/socket/ClientSocket.cpp | 2 +- webserv/socket/ClientSocket.hpp | 2 +- webserv/socket/ServerSocket.cpp | 2 +- webserv/socket/ServerSocket.hpp | 2 +- 17 files changed, 62 insertions(+), 62 deletions(-) diff --git a/webserv/client/Client.hpp b/webserv/client/Client.hpp index d57dd91..8948acd 100644 --- a/webserv/client/Client.hpp +++ b/webserv/client/Client.hpp @@ -52,7 +52,7 @@ class Client private: 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_; std::unique_ptr httpResponse_; std::unique_ptr router_; diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index f098a62..a0e46ee 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -129,22 +129,22 @@ std::map URI::getCGIEnvironment() const return env; } -const AConfig *URI::getConfig() const +const AConfig *URI::getConfig() const noexcept { return config_; } -bool URI::isFile() const +bool URI::isFile() const noexcept { return !baseName_.empty(); } -bool URI::isDirectory() const +bool URI::isDirectory() const noexcept { return baseName_.empty(); } -bool URI::isValid() const +bool URI::isValid() const noexcept { return FileUtils::isValidPath(fullPath_); } @@ -172,42 +172,42 @@ std::string URI::getCgiPath() const return cgiPath; } -const std::string &URI::getBaseName() const +const std::string &URI::getBaseName() const noexcept { return baseName_; } -std::string URI::getExtension() const +std::string URI::getExtension() const noexcept { return FileUtils::getExtension(baseName_); } -const std::string &URI::getFullPath() const +const std::string &URI::getFullPath() const noexcept { return fullPath_; } -const std::string &URI::getDir() const +const std::string &URI::getDir() const noexcept { return dir_; } -const std::string &URI::getPathInfo() const +const std::string &URI::getPathInfo() const noexcept { return pathInfo_; } -const std::string &URI::getQuery() const +const std::string &URI::getQuery() const noexcept { return query_; } -const std::string &URI::getFragment() const +const std::string &URI::getFragment() const noexcept { return fragment_; } -const std::string &URI::getAuthority() const +const std::string &URI::getAuthority() const noexcept { return authority_; } \ No newline at end of file diff --git a/webserv/handler/URI.hpp b/webserv/handler/URI.hpp index 88a771c..38f5dea 100644 --- a/webserv/handler/URI.hpp +++ b/webserv/handler/URI.hpp @@ -20,21 +20,21 @@ class URI [[nodiscard]] std::map getCGIEnvironment() const; - [[nodiscard]] bool isFile() const; - [[nodiscard]] bool isDirectory() const; - [[nodiscard]] bool isValid() const; + [[nodiscard]] bool isFile() const noexcept; + [[nodiscard]] bool isDirectory() const noexcept; + [[nodiscard]] bool isValid() const noexcept; [[nodiscard]] bool isCgi() const; - [[nodiscard]] std::string getExtension() const; + [[nodiscard]] std::string getExtension() const noexcept; [[nodiscard]] std::string getCgiPath() const; - [[nodiscard]] const AConfig *getConfig() const; - [[nodiscard]] const std::string &getBaseName() const; - [[nodiscard]] const std::string &getFullPath() const; - [[nodiscard]] const std::string &getDir() const; - [[nodiscard]] const std::string &getPathInfo() const; - [[nodiscard]] const std::string &getQuery() const; - [[nodiscard]] const std::string &getFragment() const; - [[nodiscard]] const std::string &getAuthority() const; + [[nodiscard]] const AConfig *getConfig() const noexcept; + [[nodiscard]] const std::string &getBaseName() const noexcept; + [[nodiscard]] const std::string &getFullPath() const noexcept; + [[nodiscard]] const std::string &getDir() const noexcept; + [[nodiscard]] const std::string &getPathInfo() const noexcept; + [[nodiscard]] const std::string &getQuery() const noexcept; + [[nodiscard]] const std::string &getFragment() const noexcept; + [[nodiscard]] const std::string &getAuthority() const noexcept; private: void parseUri(const std::string &uri); diff --git a/webserv/http/HttpConstants.cpp b/webserv/http/HttpConstants.cpp index 3126281..65d9149 100644 --- a/webserv/http/HttpConstants.cpp +++ b/webserv/http/HttpConstants.cpp @@ -4,7 +4,7 @@ namespace Http { -std::string getStatusCodeReason(uint16_t statusCode) +std::string getStatusCodeReason(uint16_t statusCode) noexcept { for (const auto &info : statusCodeInfos) { diff --git a/webserv/http/HttpConstants.hpp b/webserv/http/HttpConstants.hpp index 7dda7b0..5e6f6f8 100644 --- a/webserv/http/HttpConstants.hpp +++ b/webserv/http/HttpConstants.hpp @@ -66,7 +66,7 @@ static constexpr std::array statusCodeInfos {.code = StatusCode::BAD_GATEWAY, .reason = "Bad Gateway"}, {.code = StatusCode::SERVICE_UNAVAILABLE, .reason = "Service Unavailable"}}}; -std::string getStatusCodeReason(uint16_t statusCode); +std::string getStatusCodeReason(uint16_t statusCode) noexcept; // Header Names namespace Header diff --git a/webserv/http/HttpHeaders.cpp b/webserv/http/HttpHeaders.cpp index b8760e9..0c2fb10 100644 --- a/webserv/http/HttpHeaders.cpp +++ b/webserv/http/HttpHeaders.cpp @@ -7,7 +7,7 @@ #include // for tolower #include // for pair -std::optional HttpHeaders::getContentLength() const +std::optional HttpHeaders::getContentLength() const noexcept { const auto &value = this->get("Content-Length"); if (value.empty()) @@ -17,7 +17,7 @@ std::optional HttpHeaders::getContentLength() const return utils::stoul(value); } -std::optional HttpHeaders::getContentType() const +std::optional HttpHeaders::getContentType() const noexcept { const auto &value = this->get("Content-Type"); if (value.empty()) @@ -27,7 +27,7 @@ std::optional HttpHeaders::getContentType() const return value; } -std::optional HttpHeaders::getHost() const +std::optional HttpHeaders::getHost() const noexcept { const auto &value = this->get("Host"); if (value.empty()) @@ -37,19 +37,19 @@ std::optional HttpHeaders::getHost() const 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::ranges::transform(lower, lower.begin(), ::tolower); headers_[lower] = value; } -void HttpHeaders::remove(const std::string &name) +void HttpHeaders::remove(const std::string &name) noexcept { 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::ranges::transform(lower, lower.begin(), ::tolower); @@ -62,14 +62,14 @@ const std::string &HttpHeaders::get(const std::string &name) const return empty; } -bool HttpHeaders::has(const std::string &name) const +bool HttpHeaders::has(const std::string &name) const noexcept { std::string lower = name; std::ranges::transform(lower, lower.begin(), ::tolower); return headers_.contains(lower); } -void HttpHeaders::parse(const std::string &rawHeaders) +void HttpHeaders::parse(const std::string &rawHeaders) noexcept { Log::trace(LOCATION); 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; for (const auto &pair : headers_) diff --git a/webserv/http/HttpHeaders.hpp b/webserv/http/HttpHeaders.hpp index 98ec4cf..e92e803 100644 --- a/webserv/http/HttpHeaders.hpp +++ b/webserv/http/HttpHeaders.hpp @@ -18,17 +18,17 @@ class HttpHeaders { public: - [[nodiscard]] const std::string &get(const std::string &name) const; - [[nodiscard]] bool has(const std::string &name) const; + [[nodiscard]] const std::string &get(const std::string &name) const noexcept; + [[nodiscard]] bool has(const std::string &name) const noexcept; - void parse(const std::string &rawHeaders); - void add(const std::string &name, const std::string &value); - void remove(const std::string &name); + void parse(const std::string &rawHeaders) noexcept; + void add(const std::string &name, const std::string &value) noexcept; + void remove(const std::string &name) noexcept; - [[nodiscard]] std::string toString() const; - [[nodiscard]] std::optional getContentLength() const; - [[nodiscard]] std::optional getContentType() const; - [[nodiscard]] std::optional getHost() const; + [[nodiscard]] std::string toString() const noexcept; + [[nodiscard]] std::optional getContentLength() const noexcept; + [[nodiscard]] std::optional getContentType() const noexcept; + [[nodiscard]] std::optional getHost() const noexcept; private: std::unordered_map headers_; diff --git a/webserv/server/Server.cpp b/webserv/server/Server.cpp index a57381d..0588d96 100644 --- a/webserv/server/Server.cpp +++ b/webserv/server/Server.cpp @@ -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; 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); } -void Server::handleEpollHangUp(struct epoll_event *event) +void Server::handleEpollHangUp(struct epoll_event *event) const { Client &client = getClient(event->data.fd); ASocket &socket = client.getSocket(event->data.fd); diff --git a/webserv/server/Server.hpp b/webserv/server/Server.hpp index 79d48da..85f42ae 100644 --- a/webserv/server/Server.hpp +++ b/webserv/server/Server.hpp @@ -52,11 +52,11 @@ class Server void pollClients() const; 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 handleConnection(struct epoll_event *event); 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); }; diff --git a/webserv/socket/ASocket.cpp b/webserv/socket/ASocket.cpp index 4c31650..1507ce2 100644 --- a/webserv/socket/ASocket.cpp +++ b/webserv/socket/ASocket.cpp @@ -60,7 +60,7 @@ void ASocket::setNonBlocking() const } } -int ASocket::getFd() const +int ASocket::getFd() const noexcept { return fd_; } diff --git a/webserv/socket/ASocket.hpp b/webserv/socket/ASocket.hpp index c5c8afa..992c5b2 100644 --- a/webserv/socket/ASocket.hpp +++ b/webserv/socket/ASocket.hpp @@ -26,8 +26,8 @@ class ASocket virtual ~ASocket(); - [[nodiscard]] virtual Type getType() const = 0; - [[nodiscard]] int getFd() const; + [[nodiscard]] virtual Type getType() const noexcept = 0; + [[nodiscard]] int getFd() const noexcept; void callback() const; void setCallback(std::function callback); diff --git a/webserv/socket/CgiSocket.cpp b/webserv/socket/CgiSocket.cpp index 59a644b..89a870b 100644 --- a/webserv/socket/CgiSocket.cpp +++ b/webserv/socket/CgiSocket.cpp @@ -8,12 +8,12 @@ CgiSocket::CgiSocket(int fd) : ASocket(fd) Log::trace(LOCATION); } -ASocket::Type CgiSocket::getType() const +ASocket::Type CgiSocket::getType() const noexcept { return ASocket::Type::CGI_SOCKET; } -ssize_t CgiSocket::read(void *buf, size_t len) const +ssize_t CgiSocket::read(void *buf, size_t len) const { Log::trace(LOCATION); ssize_t bytesRead = ::read(getFd(), buf, len); @@ -24,7 +24,7 @@ ssize_t CgiSocket::read(void *buf, size_t len) const return bytesRead; } -ssize_t CgiSocket::write(const void *buf, size_t len) const +ssize_t CgiSocket::write(const void *buf, size_t len) const { Log::trace(LOCATION); ssize_t bytesSent = ::write(getFd(), buf, len); diff --git a/webserv/socket/CgiSocket.hpp b/webserv/socket/CgiSocket.hpp index 8e05020..e365c8b 100644 --- a/webserv/socket/CgiSocket.hpp +++ b/webserv/socket/CgiSocket.hpp @@ -11,8 +11,8 @@ class CgiSocket : public ASocket public: 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 write(const 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; }; \ No newline at end of file diff --git a/webserv/socket/ClientSocket.cpp b/webserv/socket/ClientSocket.cpp index 5ceac03..5a9685e 100644 --- a/webserv/socket/ClientSocket.cpp +++ b/webserv/socket/ClientSocket.cpp @@ -7,7 +7,7 @@ ClientSocket::ClientSocket(int fd) : ASocket(fd) Log::trace(LOCATION); } -ASocket::Type ClientSocket::getType() const +ASocket::Type ClientSocket::getType() const noexcept { return ASocket::Type::CLIENT_SOCKET; } diff --git a/webserv/socket/ClientSocket.hpp b/webserv/socket/ClientSocket.hpp index 2cf20fb..d31be0d 100644 --- a/webserv/socket/ClientSocket.hpp +++ b/webserv/socket/ClientSocket.hpp @@ -11,5 +11,5 @@ class ClientSocket : public ASocket public: explicit ClientSocket(int fd); - [[nodiscard]] ASocket::Type getType() const override; + [[nodiscard]] ASocket::Type getType() const noexcept override; }; \ No newline at end of file diff --git a/webserv/socket/ServerSocket.cpp b/webserv/socket/ServerSocket.cpp index e38c92d..2d23727 100644 --- a/webserv/socket/ServerSocket.cpp +++ b/webserv/socket/ServerSocket.cpp @@ -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; } diff --git a/webserv/socket/ServerSocket.hpp b/webserv/socket/ServerSocket.hpp index 32944e0..92c3305 100644 --- a/webserv/socket/ServerSocket.hpp +++ b/webserv/socket/ServerSocket.hpp @@ -15,6 +15,6 @@ class ServerSocket : public ASocket void listen(int backlog) 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 accept() const; }; \ No newline at end of file