more no except and const
This commit is contained in:
parent
7432cd154c
commit
259d7f1371
@ -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> httpRequest_;
|
||||
std::unique_ptr<HttpResponse> httpResponse_;
|
||||
std::unique_ptr<Router> router_;
|
||||
|
||||
@ -129,22 +129,22 @@ std::map<std::string, std::string> 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_;
|
||||
}
|
||||
@ -20,21 +20,21 @@ class URI
|
||||
|
||||
[[nodiscard]] std::map<std::string, std::string> 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);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Http
|
||||
{
|
||||
std::string getStatusCodeReason(uint16_t statusCode)
|
||||
std::string getStatusCodeReason(uint16_t statusCode) noexcept
|
||||
{
|
||||
for (const auto &info : statusCodeInfos)
|
||||
{
|
||||
|
||||
@ -66,7 +66,7 @@ static constexpr std::array<StatusCodeInfo, 12> 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
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include <cctype> // for tolower
|
||||
#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");
|
||||
if (value.empty())
|
||||
@ -17,7 +17,7 @@ std::optional<size_t> HttpHeaders::getContentLength() const
|
||||
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");
|
||||
if (value.empty())
|
||||
@ -27,7 +27,7 @@ std::optional<std::string> HttpHeaders::getContentType() const
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<std::string> HttpHeaders::getHost() const
|
||||
std::optional<std::string> HttpHeaders::getHost() const noexcept
|
||||
{
|
||||
const auto &value = this->get("Host");
|
||||
if (value.empty())
|
||||
@ -37,19 +37,19 @@ std::optional<std::string> 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_)
|
||||
|
||||
@ -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<size_t> getContentLength() const;
|
||||
[[nodiscard]] std::optional<std::string> getContentType() const;
|
||||
[[nodiscard]] std::optional<std::string> getHost() const;
|
||||
[[nodiscard]] std::string toString() const noexcept;
|
||||
[[nodiscard]] std::optional<size_t> getContentLength() const noexcept;
|
||||
[[nodiscard]] std::optional<std::string> getContentType() const noexcept;
|
||||
[[nodiscard]] std::optional<std::string> getHost() const noexcept;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> headers_;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -60,7 +60,7 @@ void ASocket::setNonBlocking() const
|
||||
}
|
||||
}
|
||||
|
||||
int ASocket::getFd() const
|
||||
int ASocket::getFd() const noexcept
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
|
||||
@ -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<void()> callback);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
};
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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<ClientSocket> accept() const;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user