35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
#include "Helpers.hpp"
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
// Should add caching here
|
|
std::string Helpers::ReadFile(std::string Path) {
|
|
std::ifstream file(Path);
|
|
std::stringstream contents;
|
|
contents << file.rdbuf();
|
|
file.close();
|
|
return contents.str();
|
|
}
|
|
|
|
void Helpers::getlineAndCount(std::basic_istream<char> &stream, uint64_t &count,
|
|
std::string &string, char delimit) {
|
|
if (delimit == '\0') {
|
|
std::getline(stream, string);
|
|
} else {
|
|
std::getline(stream, string, delimit);
|
|
}
|
|
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();
|
|
}
|