From 040043694eccc5383fe4ec2963e8243957f07659 Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 1 May 2025 13:26:25 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20added=20better=20print=20for=20request=20and=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/server/Client.hpp | 4 ++-- src/server/Client.cpp | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/includes/server/Client.hpp b/includes/server/Client.hpp index a7698e9..f4e6ac3 100644 --- a/includes/server/Client.hpp +++ b/includes/server/Client.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */ -/* Updated: 2025/05/01 12:51:51 by adjoly ### ########.fr */ +/* Updated: 2025/05/01 13:22:48 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,7 +55,7 @@ class Client { struct pollfd *_pfd; http::ARequest *_request; - // http::Response *_response; + http::Response _response; config::Server *_conf; config::Route *_route; }; diff --git a/src/server/Client.cpp b/src/server/Client.cpp index c659ae6..e035823 100644 --- a/src/server/Client.cpp +++ b/src/server/Client.cpp @@ -6,7 +6,7 @@ /* By: mmoussou whatRoute(URL(this->_request->getTarget())); + if (_route == not_nullptr) { + _log->info("euuh"); + return; + } /* std::cout << "_route is " << (_route ? "not null" : "NULL") << std::endl; */ if (!this->_route || this->_route == not_nullptr) { @@ -76,7 +80,12 @@ void Client::_getRequest(std::string request_str) { if (method == "GET") { this->_request = new http::Get(request_str); - _log->info("get request received"); + std::stringstream str; + str << "get request received on port : "; + str << _conf->getPort(); + str << " for page : "; + str << _request->getTarget(); + _log->info(str.str()); } else if (method == "DELETE") { this->_request = new http::Delete(request_str); _log->info("delete request received"); @@ -101,13 +110,19 @@ void Client::answer(void) { if (this->_request->getMethod() == "GET" || this->_request->getMethod() == "DELETE" || this->_request->getMethod() == "POST") - response = this->_request->execute().str(); + _response = this->_request->execute(); else response = "HTTP/1.1 501 Not Implemented\r\nContent-Type: " "text/html\r\n\r\n

501 Not " "Implemented

"; + response = _response.str(); send(_pfd->fd, response.c_str(), response.length(), 0); - _log->info("response sent"); + std::stringstream str; + str << "response sent, for page : "; + str << _request->getTarget(); + str << " with code : "; + str << _response.getStatusCode(); + _log->info(str.str()); } Client::~Client(void) {