fix: simplify logging for partial requests and update response handling

This commit is contained in:
Quinten 2025-11-11 16:28:35 +01:00
parent cebcb85713
commit f146f41bb8

View File

@ -137,11 +137,11 @@ void Client::request()
} }
else else
{ {
Log::debug("Received partial request", Log::debug("Received partial request");
{ // {
{"current_state", std::to_string(static_cast<uint8_t>(httpRequest_->getState()))}, // {"current_state", std::to_string(static_cast<uint8_t>(httpRequest_->getState()))},
{"buffer_length", std::to_string(bytesRead)}, // {"buffer_length", std::to_string(bytesRead)},
}); // });
} }
} }
@ -157,7 +157,7 @@ void Client::removeSocket(ASocket *socket)
sockets_.erase(socket->getFd()); sockets_.erase(socket->getFd());
} }
void Client::poll() const void Client::poll()
{ {
auto *cgiHandler = dynamic_cast<CgiHandler *>(handler_.get()); auto *cgiHandler = dynamic_cast<CgiHandler *>(handler_.get());
if (cgiHandler != nullptr) 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); ssize_t bytesSent = send(clientSocket_->getFd(), payload.data(), payload.size(), 0);
if (bytesSent < 0) if (bytesSent < 0)
{ {
@ -185,10 +185,16 @@ void Client::respond() const
} }
else 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 HttpRequest &Client::getHttpRequest() const noexcept
{ {