aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/include
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-03-19 16:53:20 +0100
committerPer Larsson <[email protected]>2022-03-19 16:53:20 +0100
commitde1c792b182aeb15168ed483a803bc93725f2f46 (patch)
treed5ea6948e6320ec43ddcba875a7c5f21a5d214cd /zenhttp/include
parentSuppress C4305 in third party includes (diff)
downloadzen-de1c792b182aeb15168ed483a803bc93725f2f46.tar.xz
zen-de1c792b182aeb15168ed483a803bc93725f2f46.zip
Added websocket stream request/response handling.
Diffstat (limited to 'zenhttp/include')
-rw-r--r--zenhttp/include/zenhttp/websocket.h44
1 files changed, 38 insertions, 6 deletions
diff --git a/zenhttp/include/zenhttp/websocket.h b/zenhttp/include/zenhttp/websocket.h
index 132dd1679..1280868ec 100644
--- a/zenhttp/include/zenhttp/websocket.h
+++ b/zenhttp/include/zenhttp/websocket.h
@@ -49,9 +49,37 @@ enum class WebSocketMessageType : uint8_t
kInvalid,
kNotification,
kRequest,
- kResponse
+ kStreamRequest,
+ kResponse,
+ kStreamResponse,
+ kStreamCompleteResponse,
+ kCount
};
+inline std::string_view
+ToString(WebSocketMessageType Type)
+{
+ switch (Type)
+ {
+ case WebSocketMessageType::kInvalid:
+ return std::string_view("Invalid");
+ case WebSocketMessageType::kNotification:
+ return std::string_view("Notification");
+ case WebSocketMessageType::kRequest:
+ return std::string_view("Request");
+ case WebSocketMessageType::kStreamRequest:
+ return std::string_view("StreamRequest");
+ case WebSocketMessageType::kResponse:
+ return std::string_view("Response");
+ case WebSocketMessageType::kStreamResponse:
+ return std::string_view("StreamResponse");
+ case WebSocketMessageType::kStreamCompleteResponse:
+ return std::string_view("StreamCompleteResponse");
+ default:
+ return std::string_view("Unknown");
+ };
+}
+
/**
* Web socket message.
*/
@@ -59,12 +87,12 @@ class WebSocketMessage
{
struct Header
{
- static constexpr uint32_t HeaderMagic = 0x7a776d68; // zwmh
+ static constexpr uint32_t ExpectedMagic = 0x7a776d68; // zwmh
uint64_t MessageSize{};
- uint32_t Magic{HeaderMagic};
+ uint32_t Magic{ExpectedMagic};
uint32_t CorrelationId{};
- uint32_t Crc32{};
+ uint32_t StatusCode{200u};
WebSocketMessageType MessageType{};
uint8_t Reserved[3] = {0};
@@ -82,11 +110,13 @@ public:
WebSocketId SocketId() const { return m_SocketId; }
void SetSocketId(WebSocketId Id) { m_SocketId = Id; }
- void SetMessageType(WebSocketMessageType MessageType);
- WebSocketMessageType MessageType() const { return m_Header.MessageType; }
uint64_t MessageSize() const { return m_Header.MessageSize; }
+ void SetMessageType(WebSocketMessageType MessageType);
void SetCorrelationId(uint32_t Id) { m_Header.CorrelationId = Id; }
uint32_t CorrelationId() const { return m_Header.CorrelationId; }
+ uint32_t StatusCode() const { m_Header.StatusCode; }
+ void SetStatusCode(uint32_t StatusCode) { m_Header.StatusCode = StatusCode; }
+ WebSocketMessageType MessageType() const { return m_Header.MessageType; }
const CbPackage& Body() const { return m_Body.value(); }
void SetBody(CbPackage&& Body);
@@ -123,6 +153,8 @@ protected:
WebSocketService() = default;
virtual void RegisterHandlers(WebSocketServer& Server) = 0;
+ void SendStreamResponse(WebSocketId SocketId, uint32_t CorrelationId, CbPackage&& StreamResponse, bool IsStreamComplete);
+ void SendStreamResponse(WebSocketId SocketId, uint32_t CorrelationId, CbObject&& StreamResponse, bool IsStreamComplete);
WebSocketServer& SocketServer()
{