mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-11 00:28:45 +02:00
「🔨」 fix(Client): fixed client just segfaulting on destructor cuz i am stupid
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/11 22:13:38 by mmoussou #+# #+# */
|
/* Created: 2025/02/11 22:13:38 by mmoussou #+# #+# */
|
||||||
/* Updated: 2025/04/22 15:00:18 by adjoly ### ########.fr */
|
/* Updated: 2025/04/23 14:38:55 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,6 +23,8 @@ public:
|
|||||||
virtual std::map<std::string, std::string> getHeaders(void) const;
|
virtual std::map<std::string, std::string> getHeaders(void) const;
|
||||||
virtual std::string getBody(void) const;
|
virtual std::string getBody(void) const;
|
||||||
|
|
||||||
|
virtual ~IMessage() {}
|
||||||
|
|
||||||
virtual void setHeaders(std::map<std::string, std::string> const headers);
|
virtual void setHeaders(std::map<std::string, std::string> const headers);
|
||||||
virtual void setBody(std::string const body);
|
virtual void setBody(std::string const body);
|
||||||
|
|
||||||
|
@ -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/04/22 11:52:22 by mmoussou ### ########.fr */
|
/* Updated: 2025/04/23 14:36:47 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ namespace http {
|
|||||||
class Response: public http::IMessage {
|
class Response: public http::IMessage {
|
||||||
public:
|
public:
|
||||||
Response(void);
|
Response(void);
|
||||||
virtual ~Response(void);
|
~Response(void);
|
||||||
|
|
||||||
std::string getProtocol(void) const;
|
std::string getProtocol(void) const;
|
||||||
uint getStatusCode(void) const;
|
uint getStatusCode(void) const;
|
||||||
|
@ -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/22 14:23:44 by adjoly ### ########.fr */
|
/* Updated: 2025/04/23 14:39:16 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class Client {
|
|||||||
int _fd;
|
int _fd;
|
||||||
struct sockaddr_in _client_addr;
|
struct sockaddr_in _client_addr;
|
||||||
http::IRequest *_request;
|
http::IRequest *_request;
|
||||||
http::Response *_response;
|
//http::Response *_response;
|
||||||
config::Server *_conf;
|
config::Server *_conf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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/20 11:21:11 by mmoussou ### ########.fr */
|
/* Updated: 2025/04/23 14:30:28 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -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/23 12:42:41 by adjoly ### ########.fr */
|
/* Updated: 2025/04/23 14:40:06 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ Client::Client(int fd, sockaddr_in socket, config::Config *conf)
|
|||||||
bytes_received = recv(fd, buffer, BUFFER_SIZE - 1, 0);
|
bytes_received = recv(fd, buffer, BUFFER_SIZE - 1, 0);
|
||||||
if (bytes_received == -1) {
|
if (bytes_received == -1) {
|
||||||
_log->error("failed to receive request");
|
_log->error("failed to receive request");
|
||||||
continue;
|
throw std::runtime_error("failed to receive request");
|
||||||
}
|
}
|
||||||
received_data += std::string(buffer, bytes_received);
|
received_data += std::string(buffer, bytes_received);
|
||||||
} while (buffer[bytes_received]);
|
} while (buffer[bytes_received]);
|
||||||
@ -59,21 +59,18 @@ void Client::_getRequest(std::string request_str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Client::answer(void) {
|
void Client::answer(void) {
|
||||||
|
(void) _client_addr;
|
||||||
std::string response;
|
std::string response;
|
||||||
(void)_client_addr;
|
|
||||||
|
|
||||||
if (this->_request->getMethod() == "GET" ||
|
if (this->_request->getMethod() == "GET" ||
|
||||||
this->_request->getMethod() == "DELETE" ||
|
this->_request->getMethod() == "DELETE" ||
|
||||||
this->_request->getMethod() == "POST")
|
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: "
|
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>";
|
||||||
"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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::~Client(void) {
|
Client::~Client(void) {
|
||||||
delete (http::Get *)(this->_request);
|
delete (http::Get *)(this->_request);
|
||||||
delete this->_response;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user