From e7c74917191a4953d495295b65732aa3549ba753 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 19 Oct 2025 00:12:50 +0200 Subject: Add new module websocket and use it Implement /api/v1/events which will send out messages when things change, such as the main controller. --- src/http.hh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/http.hh') 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 #include #include @@ -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 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 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; -- cgit v1.2.3-70-g09d2