aboutsummaryrefslogtreecommitdiff
path: root/src/http_server.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/http_server.h')
-rw-r--r--src/http_server.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/http_server.h b/src/http_server.h
new file mode 100644
index 0000000..0c4dafe
--- /dev/null
+++ b/src/http_server.h
@@ -0,0 +1,52 @@
+#ifndef HTTP_SERVER
+#define HTTP_SERVER
+
+#include <string>
+#include <map>
+#include <ws2tcpip.h>
+
+#include "http_server.h"
+
+#define HTTP_OK "200 OK"
+
+typedef std::map<std::string, std::string> header_map;
+
+class HTTPRequest {
+ private:
+ SOCKET socket;
+
+ std::string request_type;
+ std::string path;
+ header_map headers;
+ std::string body;
+
+
+ public:
+ HTTPRequest(SOCKET socket);
+ ~HTTPRequest();
+
+ void parse_headers(std::string raw);
+ void set_body(std::string body) { this->body = body; }
+ size_t content_length();
+
+ std::string get_body() { return this->body; }
+
+ void respond(std::string status_code, header_map response_headers, std::string response_body);
+ void close();
+};
+
+class HTTPServer {
+ private:
+ SOCKET sock = -1;
+
+ void parse_header();
+
+ public:
+ HTTPServer(unsigned long addr, unsigned short port);
+ ~HTTPServer();
+
+ void close();
+ HTTPRequest* receive_request();
+};
+
+#endif