🔨」 fix: fixed client bullshit things

This commit is contained in:
y-syo
2025-04-20 11:26:45 +02:00
parent a2cf80bfde
commit 5824985c93
7 changed files with 36 additions and 38 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */ /* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
/* Updated: 2025/02/14 15:43:32 by mmoussou ### ########.fr */ /* Updated: 2025/04/20 11:19:31 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,6 +27,8 @@ namespace http {
class IRequest: public http::IMessage { class IRequest: public http::IMessage {
public: public:
virtual ~IRequest(void);
virtual void parse(std::string const &data) = 0; virtual void parse(std::string const &data) = 0;
virtual http::Response execute(void) = 0; virtual http::Response execute(void) = 0;
@ -50,6 +52,7 @@ protected:
class Get: public http::IRequest { class Get: public http::IRequest {
public: public:
Get(void); Get(void);
~Get(void);
Get(std::string &data); Get(std::string &data);
void parse(std::string const &data); void parse(std::string const &data);
@ -61,6 +64,7 @@ public:
class Post: public http::IRequest { class Post: public http::IRequest {
public: public:
Post(void); Post(void);
~Post(void);
Post(std::string &data); Post(std::string &data);
void parse(std::string const &data); void parse(std::string const &data);
@ -72,6 +76,7 @@ public:
class Delete: public http::IRequest { class Delete: public http::IRequest {
public: public:
Delete(void); Delete(void);
~Delete(void);
Delete(std::string &data); Delete(std::string &data);
void parse(std::string const &data); void parse(std::string const &data);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:21:20 by mmoussou #+# #+# */ /* Created: 2025/02/03 17:21:20 by mmoussou #+# #+# */
/* Updated: 2025/03/24 15:16:39 by mmoussou ### ########.fr */ /* Updated: 2025/04/20 11:23:53 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ namespace http {
class Response: public http::IMessage { class Response: public http::IMessage {
public: public:
Response(void); Response(void);
~Response(void);
std::string getProtocol(void) const; std::string getProtocol(void) const;
uint getStatusCode(void) const; uint getStatusCode(void) const;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */ /* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */
/* Updated: 2025/04/17 18:48:25 by adjoly ### ########.fr */ /* Updated: 2025/04/20 11:25:37 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,7 @@ namespace server {
class Client { class Client {
public: public:
Client(int, sockaddr_in, config::Server *); Client(int, sockaddr_in, config::Server *);
~Client(void); virtual ~Client(void);
void answer(void); void answer(void);
@ -36,7 +36,6 @@ class Client {
http::IRequest *_request; http::IRequest *_request;
http::Response *_response; http::Response *_response;
config::Server *_conf; config::Server *_conf;
Logger *_log;
}; };
} // -namespace server } // -namespace server

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 16:07:01 by mmoussou #+# #+# */ /* Created: 2025/02/03 16:07:01 by mmoussou #+# #+# */
/* Updated: 2025/04/10 11:50:48 by mmoussou ### ########.fr */ /* Updated: 2025/04/20 11:15:51 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -75,6 +75,10 @@ http::Get::Get(void)
{ {
} }
http::Get::~Get(void)
{
}
http::Get::Get(std::string &data) http::Get::Get(std::string &data)
{ {
this->parse(data); this->parse(data);
@ -218,6 +222,10 @@ http::Delete::Delete(void)
{ {
} }
http::Delete::~Delete(void)
{
}
http::Delete::Delete(std::string &data) http::Delete::Delete(std::string &data)
{ {
this->parse(data); this->parse(data);
@ -297,6 +305,10 @@ http::Post::Post(void)
{ {
} }
http::Post::~Post(void)
{
}
http::Post::Post(std::string &data) http::Post::Post(std::string &data)
{ {
this->parse(data); this->parse(data);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:28:31 by mmoussou #+# #+# */ /* Created: 2025/02/03 17:28:31 by mmoussou #+# #+# */
/* Updated: 2025/04/08 01:11:40 by mmoussou ### ########.fr */ /* Updated: 2025/04/20 11:21:11 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,6 +27,10 @@ http::Response::Response(void)
{ {
} }
http::Response::~Response(void)
{
}
std::string http::Response::str(void) const std::string http::Response::str(void) const
{ {
std::ostringstream response; std::ostringstream response;

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */ /* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
/* Updated: 2025/04/18 10:03:57 by adjoly ### ########.fr */ /* Updated: 2025/04/20 11:07:47 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,31 +15,8 @@
using namespace server; using namespace server;
/*class Client { Client::Client(int fd, sockaddr_in socket, config::Server *conf): _fd(fd), _client_addr(socket), _conf(conf)
public:
Client(int, sockaddr_in, config::Config *);
~Client(void);
void answer(void);
private:
void getRequest(void);
int _fd;
struct sockaddr_in _client_addr;
http::IRequest *_request;
http::Response *_response;
config::Server *_conf;
std::string _request_method;
};*/
Client::Client(int fd, sockaddr_in socket, config::Server *conf, Logger *log)
{ {
this->_fd = fd;
this->_client_addr = socket;
this->_conf = conf;
this->_log = log;
std::string received_data; std::string received_data;
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
ssize_t bytes_received; ssize_t bytes_received;
@ -57,7 +34,7 @@ Client::Client(int fd, sockaddr_in socket, config::Server *conf, Logger *log)
while (buffer[bytes_received]); while (buffer[bytes_received]);
this->getRequest(request_str); this->_getRequest(received_data);
} }
void Client::_getRequest(std::string request_str) void Client::_getRequest(std::string request_str)
@ -91,8 +68,8 @@ void Client::answer(void)
{ {
std::string response; std::string response;
if (this->_request == "GET" || this->_request == "DELETE" || this->_request == "POST") if (this->_request->getMethod() == "GET" || this->_request->getMethod() == "DELETE" || this->_request->getMethod() == "POST")
response = this->_request.execute().str(); response = this->_request->execute().str();
else else
response = "HTTP/1.1 501 Not Implemented\r\nContent-Type: text/html\r\n\r\n<html><body><h1>501 Not Implemented</h1></body></html>"; response = "HTTP/1.1 501 Not Implemented\r\nContent-Type: text/html\r\n\r\n<html><body><h1>501 Not Implemented</h1></body></html>";
send(this->_fd, response.c_str(), response.length(), 0); send(this->_fd, response.c_str(), response.length(), 0);
@ -101,6 +78,6 @@ void Client::answer(void)
Client::~Client(void) Client::~Client(void)
{ {
delete this->_request; delete (http::Get *)(this->_request);
delete this->_response; delete this->_response;
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */ /* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
/* Updated: 2025/04/18 09:37:32 by adjoly ### ########.fr */ /* Updated: 2025/04/20 10:58:26 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -78,5 +78,5 @@ int Server::_createSocket(std::string host, int port) {
} }
void Server::_handle_client(int fd, sockaddr_in client_addr, struct pollfd poll_fd) { void Server::_handle_client(int fd, sockaddr_in client_addr, struct pollfd poll_fd) {
server::Client *client = new server::Client(fd, client_addr, ); server::Client *client = new server::Client(fd, client_addr, NULL);
} }