From f146f41bb834910752c133f04f7e54a266437b9c Mon Sep 17 00:00:00 2001 From: Quinten Date: Tue, 11 Nov 2025 16:28:35 +0100 Subject: [PATCH] fix: simplify logging for partial requests and update response handling --- webserv/client/Client.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/webserv/client/Client.cpp b/webserv/client/Client.cpp index fadd529..3569e13 100644 --- a/webserv/client/Client.cpp +++ b/webserv/client/Client.cpp @@ -137,11 +137,11 @@ void Client::request() } else { - Log::debug("Received partial request", - { - {"current_state", std::to_string(static_cast(httpRequest_->getState()))}, - {"buffer_length", std::to_string(bytesRead)}, - }); + Log::debug("Received partial request"); + // { + // {"current_state", std::to_string(static_cast(httpRequest_->getState()))}, + // {"buffer_length", std::to_string(bytesRead)}, + // }); } } @@ -157,7 +157,7 @@ void Client::removeSocket(ASocket *socket) sockets_.erase(socket->getFd()); } -void Client::poll() const +void Client::poll() { auto *cgiHandler = dynamic_cast(handler_.get()); if (cgiHandler != nullptr) @@ -175,9 +175,9 @@ void Client::poll() const } } -void Client::respond() const +void Client::respond() { - auto payload = httpResponse_->toBytes(); + auto payload = httpResponse_->toBytes(writeOffset_); ssize_t bytesSent = send(clientSocket_->getFd(), payload.data(), payload.size(), 0); if (bytesSent < 0) { @@ -185,9 +185,15 @@ void Client::respond() const } else { - Log::debug("Sent " + std::to_string(bytesSent) + " bytes to: " + clientSocket_->toString()); + writeOffset_ += bytesSent; + Log::debug("Sent " + std::to_string(bytesSent) + " bytes out of " + std::to_string(writeOffset_ + payload.size()) + + " to: " + clientSocket_->toString()); + } + if (payload.empty()) + { + Log::info("Closing connection to client: " + clientSocket_->toString()); + server_.disconnect(*this); // ! CRITICAL: RETURN IMMEDIATELY } - server_.disconnect(*this); // ! CRITICAL: RETURN IMMEDIATELY } HttpRequest &Client::getHttpRequest() const noexcept