1
0
forked from cat/WebBase

Testing POST and upload

This commit is contained in:
2025-06-26 02:55:47 +03:00
parent 7716494a1c
commit b32e7f5d70
2 changed files with 23 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
#include "Helpers.hpp"
#include "main.hpp"
#include <iostream>
void HTTPrequest::start() {
// Possible Logging here
@@ -11,6 +12,9 @@ void HTTPrequest::readData() {
// Reading happens here
//
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(
buffer.prepare(2048),
[this, self](std::error_code error, std::size_t packageSize) {
@@ -32,7 +36,12 @@ void HTTPrequest::readData() {
// some gangster shit right here
std::getline(stream, value);
request.insert({key, value});
if (type == "GET") {
request.insert({key, value});
} else {
std::cout << key << " " << value << "\n";
}
}
processRequest(type, path, request); // This writes data too
@@ -47,16 +56,21 @@ void HTTPrequest::processRequest(
//
// This is where we will process requests
//
uint64_t pathHash = Helpers::Pathhash(requestPath);
// This is very much temp
if (requestType != "GET") {
writeData(Helpers::GenerateResponse("403 Forbidden", "text/text",
"POST requests are not allowed!"));
if (requestType == "POST") {
switch (pathHash) {
case "/upload"_hash:
writeData(Helpers::GenerateResponse("501 Not Implemented", "text/text",
"This path is not implemented yet!"));
return;
}
return;
}
// This can be further refactored to just "File send"
switch (Helpers::Pathhash(requestPath)) {
switch (pathHash) {
case "/"_hash:
writeData(Helpers::GenerateResponse("200 OK", "text/html",
Helpers::ReadFile("www/index.html")));