forked from cat/WebBase
Added a simple POST response and more work on respond string
This commit is contained in:
21
src/HTTP.cpp
21
src/HTTP.cpp
@@ -2,6 +2,7 @@
|
||||
#include "main.hpp"
|
||||
#include <asio/impl/write.hpp>
|
||||
#include <cstddef>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
@@ -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("<html><head><title>Hello "
|
||||
"you!</title></head><body><h1>Test</h1><p>pretty "
|
||||
"cool</p></body></html>");
|
||||
sock.close(); // Responded
|
||||
responseStream << "200 OK" << responseMeta
|
||||
<< "<html><head><title>Hello "
|
||||
"you!</title></head><body><h1>Test</h1><p>pretty "
|
||||
"cool</p></body></html>";
|
||||
break;
|
||||
}
|
||||
writeData(responseStream.str());
|
||||
}
|
||||
|
||||
void HTTPrequest::writeData(std::string data) {
|
||||
|
Reference in New Issue
Block a user