1
0
forked from cat/WebBase

Basic request reading

This commit is contained in:
2025-06-25 22:24:32 +03:00
parent c046cdc775
commit 98c4eafdbe
2 changed files with 20 additions and 4 deletions

View File

@@ -6,14 +6,27 @@ void HTTPrequest::start() {
}
void HTTPrequest::readData() {
std::shared_ptr<HTTPrequest> self(shared_from_this());
//
// Reading happens here
//
std::shared_ptr<HTTPrequest> self(shared_from_this());
sock.async_read_some(
buffer.prepare(1024),
[this, self](std::error_code error, std::size_t packageSize) {
if (!error) {
buffer.commit(packageSize);
std::istream stream(&buffer);
std::string request(packageSize, '\0');
stream.read(request.data(), packageSize);
std::cout << request << std::endl;
readData();
}
});
}
void HTTPrequest::processRequest(std::error_code ec, std::size_t size) {
void HTTPrequest::processRequest(std::string request) {
//
// This is where we will process requests
//

View File

@@ -12,6 +12,9 @@
#include <exception>
#include <iostream>
#include <istream>
#include <string>
#include <system_error>
#define IP "127.0.0.1"
#define PORT 8000
@@ -31,7 +34,7 @@ public:
private:
HTTPrequest(asio::io_context &context);
void readData();
void processRequest(std::error_code ec, std::size_t size);
void processRequest(std::string request);
void writeData(std::string data);
asio::ip::tcp::socket sock;