HTTP bodies should work nicely, files are reorganised, www is reverted
This commit is contained in:
52
src/Main.hpp
Normal file
52
src/Main.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <asio.hpp>
|
||||
#include <asio/buffer.hpp>
|
||||
#include <asio/error_code.hpp>
|
||||
#include <asio/impl/read.hpp>
|
||||
#include <asio/impl/read_until.hpp>
|
||||
#include <asio/impl/write.hpp>
|
||||
#include <asio/io_context.hpp>
|
||||
#include <asio/ip/address.hpp>
|
||||
#include <asio/ip/tcp.hpp>
|
||||
#include <asio/placeholders.hpp>
|
||||
#include <asio/streambuf.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#define IP "127.0.0.1"
|
||||
#define PORT 8000
|
||||
using asocket = asio::ip::tcp::socket;
|
||||
using asocket_ptr = std::shared_ptr<asocket>;
|
||||
|
||||
// We handle HTTP requests with readData, writeData, and processRequest
|
||||
class HTTPrequest : public std::enable_shared_from_this<HTTPrequest> {
|
||||
public:
|
||||
typedef std::shared_ptr<HTTPrequest> HTTPrequest_ptr;
|
||||
|
||||
asio::ip::tcp::socket &socket();
|
||||
static HTTPrequest_ptr create(asio::io_context &context);
|
||||
|
||||
void start();
|
||||
|
||||
private:
|
||||
HTTPrequest(asio::io_context &context);
|
||||
void processHTTPHeader();
|
||||
void processRequest(std::string requestType, std::string requestPath,
|
||||
std::unordered_map<std::string, std::string> request,
|
||||
std::unordered_map<std::string, std::string> args);
|
||||
void writeData(std::string data);
|
||||
|
||||
asio::ip::tcp::socket sock;
|
||||
asio::streambuf buffer;
|
||||
};
|
||||
|
||||
// Server manages connections/requests
|
||||
class Webserver : public std::enable_shared_from_this<Webserver> {
|
||||
public:
|
||||
Webserver(asio::io_context &context);
|
||||
|
||||
private:
|
||||
void begin();
|
||||
asio::io_context &io;
|
||||
asio::ip::tcp::acceptor accept;
|
||||
};
|
Reference in New Issue
Block a user