Basic request reading
This commit is contained in:
19
src/HTTP.cpp
19
src/HTTP.cpp
@@ -6,14 +6,27 @@ void HTTPrequest::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HTTPrequest::readData() {
|
void HTTPrequest::readData() {
|
||||||
std::shared_ptr<HTTPrequest> self(shared_from_this());
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Reading happens here
|
// 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
|
// This is where we will process requests
|
||||||
//
|
//
|
||||||
|
@@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
|
|
||||||
#define IP "127.0.0.1"
|
#define IP "127.0.0.1"
|
||||||
#define PORT 8000
|
#define PORT 8000
|
||||||
@@ -31,7 +34,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
HTTPrequest(asio::io_context &context);
|
HTTPrequest(asio::io_context &context);
|
||||||
void readData();
|
void readData();
|
||||||
void processRequest(std::error_code ec, std::size_t size);
|
void processRequest(std::string request);
|
||||||
void writeData(std::string data);
|
void writeData(std::string data);
|
||||||
|
|
||||||
asio::ip::tcp::socket sock;
|
asio::ip::tcp::socket sock;
|
||||||
|
Reference in New Issue
Block a user