summaryrefslogtreecommitdiff
path: root/src/http.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-10-19 00:12:50 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-10-19 00:31:19 +0200
commite7c74917191a4953d495295b65732aa3549ba753 (patch)
treefde3fc6080786b3e3e4526b3793bacbb390d2b17 /src/http.hh
parent4f6ead7c2c646b6b866274299c05d08170d2dfb0 (diff)
Add new module websocket and use it
Implement /api/v1/events which will send out messages when things change, such as the main controller.
Diffstat (limited to 'src/http.hh')
-rw-r--r--src/http.hh28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/http.hh b/src/http.hh
index ca3f7d4..d85420e 100644
--- a/src/http.hh
+++ b/src/http.hh
@@ -1,6 +1,8 @@
#ifndef HTTP_HH
#define HTTP_HH
+#include "unique_fd.hh"
+
#include <cstdint>
#include <memory>
#include <optional>
@@ -23,8 +25,10 @@ class Config;
namespace http {
enum class StatusCode : uint16_t {
+ kSwitchingProtocols = 101,
kOK = 200,
kNoContent = 204,
+ kBadRequest = 400,
kNotFound = 404,
kMethodNotAllowed = 405,
};
@@ -96,6 +100,16 @@ class Request {
virtual std::string_view method() const = 0;
[[nodiscard]]
virtual std::string_view path() const = 0;
+ [[nodiscard]]
+ virtual std::string_view body() const = 0;
+
+ [[nodiscard]]
+ virtual bool header_contains(std::string_view name,
+ std::string_view value) const = 0;
+
+ [[nodiscard]]
+ virtual std::optional<std::string_view> header_value(
+ std::string_view name) const = 0;
protected:
Request() = default;
@@ -103,6 +117,16 @@ class Request {
Request& operator=(Request const&) = delete;
};
+class SocketReceiver {
+ public:
+ virtual ~SocketReceiver() = default;
+
+ virtual void receive(unique_fd&& fd) = 0;
+
+ protected:
+ SocketReceiver() = default;
+};
+
class Response {
public:
virtual ~Response() = default;
@@ -115,6 +139,8 @@ class Response {
virtual Builder& add_header(std::string_view name,
std::string_view value) = 0;
+ virtual Builder& take_over(SocketReceiver& receiver) = 0;
+
[[nodiscard]]
virtual std::unique_ptr<Response> build() const = 0;
@@ -140,6 +166,8 @@ class Response {
// Returns true while there is more data to write.
virtual bool write(Buffer& buffer) = 0;
+ virtual SocketReceiver* socket_receiver() const = 0;
+
protected:
Response() = default;
Response(Response const&) = delete;