From fb3f1e7c379907b330538042eb227dc7956efc21 Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 4 Jul 2025 21:53:45 +0300 Subject: [PATCH] Absorbtion of generate response --- src/HTTP.cpp | 8 +++++++- src/Helpers.cpp | 10 ---------- src/Helpers.hpp | 2 -- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/HTTP.cpp b/src/HTTP.cpp index f4875d4..dbfa505 100644 --- a/src/HTTP.cpp +++ b/src/HTTP.cpp @@ -20,7 +20,13 @@ void HTTPrequest::processRequest() { void HTTPrequest::sendResponse(std::string status, std::string mime, std::string data) { // Logging here perhaps - asio::write(sock, asio::buffer(data)); + std::stringstream output; + output << "HTTP/1.1 " << status << "\n" + << "Content-Type: " << mime << "\nContent-Length: " << data.size() + << "\nConnection: close\n\n" + << data; + + asio::write(sock, asio::buffer(output.str())); } // ================= CLASS HANDLING SPECIFIC ================= diff --git a/src/Helpers.cpp b/src/Helpers.cpp index e68a012..3f71786 100644 --- a/src/Helpers.cpp +++ b/src/Helpers.cpp @@ -22,13 +22,3 @@ void Helpers::getlineAndCount(std::basic_istream &stream, uint64_t &count, count += string.size() + 1; // Delimiter return; } -std::string Helpers::GenerateResponse(std::string statusCode, - std::string contentType, - std::string content) { - std::stringstream output; - output << "HTTP/1.1 " << statusCode << "\n" - << "Content-Type: " << contentType - << "\nContent-Length: " << content.size() << "\nConnection: close\n\n" - << content; - return output.str(); -} diff --git a/src/Helpers.hpp b/src/Helpers.hpp index a26b817..ba75344 100644 --- a/src/Helpers.hpp +++ b/src/Helpers.hpp @@ -5,6 +5,4 @@ namespace Helpers { std::string ReadFile(std::string Path); void getlineAndCount(std::basic_istream &stream, uint64_t &count, std::string &string, char delimit = '\0'); -std::string GenerateResponse(std::string statusCode, std::string contentType, - std::string content); } // namespace Helpers