diff options
Diffstat (limited to 'src/http.hh')
| -rw-r--r-- | src/http.hh | 28 |
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; |
