From b32e7f5d70d8d0d67a8043caaeb97cb2e7661fab Mon Sep 17 00:00:00 2001 From: cat Date: Thu, 26 Jun 2025 02:55:47 +0300 Subject: [PATCH] Testing POST and upload --- src/HTTP.cpp | 24 +++++++++++++++++++----- www/index.html | 4 ++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/HTTP.cpp b/src/HTTP.cpp index 4b063a1..69c0a93 100644 --- a/src/HTTP.cpp +++ b/src/HTTP.cpp @@ -1,5 +1,6 @@ #include "Helpers.hpp" #include "main.hpp" +#include void HTTPrequest::start() { // Possible Logging here @@ -11,6 +12,9 @@ void HTTPrequest::readData() { // Reading happens here // std::shared_ptr 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"))); diff --git a/www/index.html b/www/index.html index a6792bf..5a4af6f 100644 --- a/www/index.html +++ b/www/index.html @@ -9,6 +9,10 @@

Test

+
+ + +