Template
1
0

Added a simple POST response and more work on respond string

This commit is contained in:
2025-06-25 23:47:46 +03:00
parent bc8523b73e
commit 095dd8ddf9

View File

@@ -2,6 +2,7 @@
#include "main.hpp" #include "main.hpp"
#include <asio/impl/write.hpp> #include <asio/impl/write.hpp>
#include <cstddef> #include <cstddef>
#include <sstream>
#include <string> #include <string>
#include <system_error> #include <system_error>
@@ -40,7 +41,7 @@ void HTTPrequest::readData() {
} }
processRequest(type, path, request); // This writes data too 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 // 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") { if (requestType != "GET") {
responseStream << "403 Forbidden" << responseMeta << "No POST allowed";
writeData(responseStream.str());
return; return;
} }
// This needs to read from a file instead of by hand
switch (Helpers::Pathhash(requestPath)) { switch (Helpers::Pathhash(requestPath)) {
case "/"_hash: case "/"_hash:
writeData("<html><head><title>Hello " responseStream << "200 OK" << responseMeta
<< "<html><head><title>Hello "
"you!</title></head><body><h1>Test</h1><p>pretty " "you!</title></head><body><h1>Test</h1><p>pretty "
"cool</p></body></html>"); "cool</p></body></html>";
sock.close(); // Responded
break; break;
} }
writeData(responseStream.str());
} }
void HTTPrequest::writeData(std::string data) { void HTTPrequest::writeData(std::string data) {