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 "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
|
||||||
"you!</title></head><body><h1>Test</h1><p>pretty "
|
<< "<html><head><title>Hello "
|
||||||
"cool</p></body></html>");
|
"you!</title></head><body><h1>Test</h1><p>pretty "
|
||||||
sock.close(); // Responded
|
"cool</p></body></html>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
writeData(responseStream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPrequest::writeData(std::string data) {
|
void HTTPrequest::writeData(std::string data) {
|
||||||
|
Reference in New Issue
Block a user