diff --git a/src/HTTP.cpp b/src/HTTP.cpp index 499d519..a1ad841 100644 --- a/src/HTTP.cpp +++ b/src/HTTP.cpp @@ -2,6 +2,7 @@ #include "main.hpp" #include #include +#include #include #include @@ -40,7 +41,7 @@ void HTTPrequest::readData() { } processRequest(type, path, request); // This writes data too - readData(); // Loop + sock.close(); // Responded } }); } @@ -51,17 +52,27 @@ 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()); return; } + + // This needs to read from a file instead of by hand switch (Helpers::Pathhash(requestPath)) { case "/"_hash: - writeData("Hello " - "you!

Test

pretty " - "cool

"); - sock.close(); // Responded + responseStream << "200 OK" << responseMeta + << "Hello " + "you!

Test

pretty " + "cool

"; break; } + writeData(responseStream.str()); } void HTTPrequest::writeData(std::string data) {