Template
1
0

Absorbtion of generate response

This commit is contained in:
2025-07-04 21:53:45 +03:00
parent cc3eb54b3b
commit fb3f1e7c37
3 changed files with 7 additions and 13 deletions

View File

@@ -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 =================

View File

@@ -22,13 +22,3 @@ void Helpers::getlineAndCount(std::basic_istream<char> &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();
}

View File

@@ -5,6 +5,4 @@ namespace Helpers {
std::string ReadFile(std::string Path);
void getlineAndCount(std::basic_istream<char> &stream, uint64_t &count,
std::string &string, char delimit = '\0');
std::string GenerateResponse(std::string statusCode, std::string contentType,
std::string content);
} // namespace Helpers