Added proper file reading
This commit is contained in:
20
src/HTTP.cpp
20
src/HTTP.cpp
@@ -47,25 +47,25 @@ void HTTPrequest::processRequest(
|
||||
//
|
||||
// This is where we will process requests
|
||||
//
|
||||
std::stringstream responseStream;
|
||||
std::string responseMeta = "\nContent-Type: text/html\nConnection: close\n\n";
|
||||
responseStream << "HTTP/1.1 ";
|
||||
|
||||
// This is very much temp
|
||||
if (requestType != "GET") {
|
||||
responseStream << "403 Forbidden" << responseMeta << "No POST allowed";
|
||||
writeData(responseStream.str());
|
||||
writeData(Helpers::GenerateResponse("403 Forbidden", "text/text",
|
||||
"POST requests are not allowed!"));
|
||||
return;
|
||||
}
|
||||
|
||||
// This needs to read from a file instead of by hand
|
||||
// This can be further refactored to just "File send"
|
||||
switch (Helpers::Pathhash(requestPath)) {
|
||||
case "/"_hash:
|
||||
responseStream << "200 OK" << responseMeta
|
||||
<< Helpers::ReadFile("www/index.html");
|
||||
break;
|
||||
writeData(Helpers::GenerateResponse("200 OK", "text/html",
|
||||
Helpers::ReadFile("www/index.html")));
|
||||
return;
|
||||
default:
|
||||
writeData(Helpers::GenerateResponse("404 Not Found", "text/html",
|
||||
"Could not find that file!!"));
|
||||
return;
|
||||
}
|
||||
writeData(responseStream.str());
|
||||
}
|
||||
|
||||
void HTTPrequest::writeData(std::string data) {
|
||||
|
Reference in New Issue
Block a user