diff --git a/webserv/config/directive/ADirective.cpp b/webserv/config/directive/ADirective.cpp index 5c39545..dd1c082 100644 --- a/webserv/config/directive/ADirective.cpp +++ b/webserv/config/directive/ADirective.cpp @@ -1,6 +1,11 @@ #include #include // for DirectiveValue, operator<< +#include // for move + +ADirective::ADirective(std::string name) : name_(std::move(name)) //TODO Move here but derived classes take const ref +{ +} DirectiveValue ADirective::getValue() const { diff --git a/webserv/config/directive/ADirective.hpp b/webserv/config/directive/ADirective.hpp index 85129d0..7d170b8 100644 --- a/webserv/config/directive/ADirective.hpp +++ b/webserv/config/directive/ADirective.hpp @@ -4,14 +4,13 @@ #include // for ostream #include // for string, basic_string -#include // for move class ADirective { public: ADirective() = delete; - ADirective(std::string name) : name_(std::move(name)) {} + ADirective(std::string name); ADirective(const ADirective &other) = delete; ADirective &operator=(const ADirective &other) = delete; diff --git a/webserv/handler/FileHandler.hpp b/webserv/handler/FileHandler.hpp index aa6af63..20a5533 100644 --- a/webserv/handler/FileHandler.hpp +++ b/webserv/handler/FileHandler.hpp @@ -17,6 +17,13 @@ class FileHandler public: FileHandler(const AConfig *config, const URI &uri); + FileHandler(const FileHandler &other) = delete; + FileHandler(FileHandler &&other) noexcept = delete; + FileHandler &operator=(const FileHandler &other) = delete; + FileHandler &operator=(FileHandler &&other) noexcept = delete; + + ~FileHandler() = default; + [[nodiscard]] std::unique_ptr getResponse() const; private: diff --git a/webserv/http/HttpHeaders.hpp b/webserv/http/HttpHeaders.hpp index bf61e3e..98ec4cf 100644 --- a/webserv/http/HttpHeaders.hpp +++ b/webserv/http/HttpHeaders.hpp @@ -18,18 +18,17 @@ class HttpHeaders { public: - const std::string &get(const std::string &name) const; - bool has(const std::string &name) const; + [[nodiscard]] const std::string &get(const std::string &name) const; + [[nodiscard]] bool has(const std::string &name) const; void parse(const std::string &rawHeaders); void add(const std::string &name, const std::string &value); void remove(const std::string &name); - std::string toString() const; - - std::optional getContentLength() const; - std::optional getContentType() const; - std::optional getHost() const; + [[nodiscard]] std::string toString() const; + [[nodiscard]] std::optional getContentLength() const; + [[nodiscard]] std::optional getContentType() const; + [[nodiscard]] std::optional getHost() const; private: std::unordered_map headers_; diff --git a/webserv/http/HttpRequest.cpp b/webserv/http/HttpRequest.cpp index a16097e..99bd481 100644 --- a/webserv/http/HttpRequest.cpp +++ b/webserv/http/HttpRequest.cpp @@ -223,3 +223,19 @@ void HttpRequest::reset() body_.clear(); // contentLength_ = 0; } + +const std::string &HttpRequest::getMethod() const +{ + return method_; +} + +const std::string &HttpRequest::getTarget() const +{ + return target_; +} + +const std::string &HttpRequest::getHttpVersion() const +{ + return httpVersion_; +} + diff --git a/webserv/http/HttpRequest.hpp b/webserv/http/HttpRequest.hpp index fdfe39d..1893ed4 100644 --- a/webserv/http/HttpRequest.hpp +++ b/webserv/http/HttpRequest.hpp @@ -32,27 +32,24 @@ class HttpRequest ~HttpRequest(); [[nodiscard]] State getState() const; - void setState(State state); [[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]] const std::string &getMethod() const { return method_; } - - [[nodiscard]] const std::string &getTarget() const { return target_; } - - [[nodiscard]] const std::string &getHttpVersion() const { return httpVersion_; } - + void setState(State state); void receiveData(const char *data, size_t length); void reset(); private: - void parseBuffer(); [[nodiscard]] bool parseBufferforRequestLine(); [[nodiscard]] bool parseBufferforHeaders(); [[nodiscard]] bool parseHeaderLine(); [[nodiscard]] bool parseBufferforBody(); [[nodiscard]] bool parseBufferforChunkedBody(); + void parseBuffer(); void parseContentLength(); Client *client_; @@ -66,7 +63,4 @@ class HttpRequest std::string method_; std::string target_; std::string httpVersion_; - // std::string requestLine_; - // std::string headers_; - // size_t contentLength_ = 0; }; diff --git a/webserv/server/Server.hpp b/webserv/server/Server.hpp index 199c352..d5a16f6 100644 --- a/webserv/server/Server.hpp +++ b/webserv/server/Server.hpp @@ -25,13 +25,10 @@ class Server Server() = delete; Server(const ConfigManager &configManager); - Server(const Server &other) = delete; // Disable copy constructor - Server &operator=(const Server &other) = delete; // Disable copy assignment - Server(Server &&other) noexcept = delete; // Move constructor - Server &operator=(Server &&other) noexcept = delete; // Move assignment - - // The constructor must initialize the reference member 'configManager' - // Implementation should be in the .cpp file using an initializer list + Server(const Server &other) = delete; + Server &operator=(const Server &other) = delete; + Server(Server &&other) noexcept = delete; + Server &operator=(Server &&other) noexcept = delete; ~Server(); @@ -49,7 +46,6 @@ class Server const ConfigManager &configManager_; std::vector> listeners_; std::set listener_fds_; - // std::unordered_map> clients_; std::vector> clients_; std::unordered_map socketToClient_; diff --git a/webserv/socket/CGISocket.hpp b/webserv/socket/CGISocket.hpp index 4b01334..ac000ff 100644 --- a/webserv/socket/CGISocket.hpp +++ b/webserv/socket/CGISocket.hpp @@ -9,7 +9,7 @@ class CGISocket : public ASocket { public: - [[nodiscard]] ASocket::Type getType() const override; - explicit CGISocket(int fd); + + [[nodiscard]] ASocket::Type getType() const override; }; \ No newline at end of file diff --git a/webserv/socket/ClientSocket.hpp b/webserv/socket/ClientSocket.hpp index e27b7ed..2cf20fb 100644 --- a/webserv/socket/ClientSocket.hpp +++ b/webserv/socket/ClientSocket.hpp @@ -9,7 +9,7 @@ class ClientSocket : public ASocket { public: - [[nodiscard]] ASocket::Type getType() const override; - explicit ClientSocket(int fd); + + [[nodiscard]] ASocket::Type getType() const override; }; \ No newline at end of file diff --git a/webserv/socket/ServerSocket.hpp b/webserv/socket/ServerSocket.hpp index 69af39f..32944e0 100644 --- a/webserv/socket/ServerSocket.hpp +++ b/webserv/socket/ServerSocket.hpp @@ -10,13 +10,11 @@ class ServerSocket : public ASocket { public: ServerSocket(); - ServerSocket(int fd); void listen(int backlog) const; void bind(const std::string &host, int port) const; [[nodiscard]] ASocket::Type getType() const override; - [[nodiscard]] std::unique_ptr accept() const; }; \ No newline at end of file