forked from cat/WebBase
Testing POST and upload
This commit is contained in:
22
src/HTTP.cpp
22
src/HTTP.cpp
@@ -1,5 +1,6 @@
|
|||||||
#include "Helpers.hpp"
|
#include "Helpers.hpp"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void HTTPrequest::start() {
|
void HTTPrequest::start() {
|
||||||
// Possible Logging here
|
// Possible Logging here
|
||||||
@@ -11,6 +12,9 @@ void HTTPrequest::readData() {
|
|||||||
// Reading happens here
|
// Reading happens here
|
||||||
//
|
//
|
||||||
std::shared_ptr<HTTPrequest> self(shared_from_this());
|
std::shared_ptr<HTTPrequest> self(shared_from_this());
|
||||||
|
|
||||||
|
// TODO: Read until headers, headers contains the file size then allocate that
|
||||||
|
// much memory on buffer, and THEN start reading the file
|
||||||
sock.async_read_some(
|
sock.async_read_some(
|
||||||
buffer.prepare(2048),
|
buffer.prepare(2048),
|
||||||
[this, self](std::error_code error, std::size_t packageSize) {
|
[this, self](std::error_code error, std::size_t packageSize) {
|
||||||
@@ -32,7 +36,12 @@ void HTTPrequest::readData() {
|
|||||||
// some gangster shit right here
|
// some gangster shit right here
|
||||||
std::getline(stream, value);
|
std::getline(stream, value);
|
||||||
|
|
||||||
|
if (type == "GET") {
|
||||||
|
|
||||||
request.insert({key, value});
|
request.insert({key, value});
|
||||||
|
} else {
|
||||||
|
std::cout << key << " " << value << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processRequest(type, path, request); // This writes data too
|
processRequest(type, path, request); // This writes data too
|
||||||
@@ -47,16 +56,21 @@ void HTTPrequest::processRequest(
|
|||||||
//
|
//
|
||||||
// This is where we will process requests
|
// This is where we will process requests
|
||||||
//
|
//
|
||||||
|
uint64_t pathHash = Helpers::Pathhash(requestPath);
|
||||||
|
|
||||||
// This is very much temp
|
// This is very much temp
|
||||||
if (requestType != "GET") {
|
if (requestType == "POST") {
|
||||||
writeData(Helpers::GenerateResponse("403 Forbidden", "text/text",
|
switch (pathHash) {
|
||||||
"POST requests are not allowed!"));
|
case "/upload"_hash:
|
||||||
|
writeData(Helpers::GenerateResponse("501 Not Implemented", "text/text",
|
||||||
|
"This path is not implemented yet!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This can be further refactored to just "File send"
|
// This can be further refactored to just "File send"
|
||||||
switch (Helpers::Pathhash(requestPath)) {
|
switch (pathHash) {
|
||||||
case "/"_hash:
|
case "/"_hash:
|
||||||
writeData(Helpers::GenerateResponse("200 OK", "text/html",
|
writeData(Helpers::GenerateResponse("200 OK", "text/html",
|
||||||
Helpers::ReadFile("www/index.html")));
|
Helpers::ReadFile("www/index.html")));
|
||||||
|
@@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Test</h1>
|
<h1>Test</h1>
|
||||||
|
<form action="/upload" method="POST" enctype="multipart/form-data">
|
||||||
|
<input type="file" name="uploaded_file">
|
||||||
|
<input type="submit" value="Upload">
|
||||||
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user