aboutsummaryrefslogtreecommitdiff
path: root/zenserver/testing/httptest.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-21 14:22:38 +0100
committerPer Larsson <[email protected]>2022-02-21 14:22:38 +0100
commitfd9f9086b3ddd0c38fa87d7e49f6341dacdcc125 (patch)
tree50be00e62f1e0d3a0521d08d5c7f00fe7787e014 /zenserver/testing/httptest.cpp
parentBasic websocket service and test. (diff)
downloadzen-fd9f9086b3ddd0c38fa87d7e49f6341dacdcc125.tar.xz
zen-fd9f9086b3ddd0c38fa87d7e49f6341dacdcc125.zip
Refactored websocket message.
Diffstat (limited to 'zenserver/testing/httptest.cpp')
-rw-r--r--zenserver/testing/httptest.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/zenserver/testing/httptest.cpp b/zenserver/testing/httptest.cpp
index 41a4f064b..10b69c469 100644
--- a/zenserver/testing/httptest.cpp
+++ b/zenserver/testing/httptest.cpp
@@ -8,6 +8,8 @@
namespace zen {
+using namespace std::literals;
+
HttpTestingService::HttpTestingService()
{
m_Router.RegisterRoute(
@@ -136,29 +138,34 @@ HttpTestingService::HandlePackageRequest(HttpServerRequest& HttpServiceRequest)
return (InsertResult.first->second = new PackageHandler(*this, RequestId)).Get();
}
-bool
-HttpTestingService::HandleMessage(WebSocketId SocketId, const CbPackage& Msg)
+void
+HttpTestingService::RegisterHandlers(WebSocketServer& Server)
{
- using namespace std::literals;
+ Server.RegisterRequestHandler("SayHello"sv, *this);
+}
- CbObject Request = Msg.GetObject();
+bool
+HttpTestingService::HandleRequest(const WebSocketMessage& RequestMsg)
+{
+ CbObjectView Request = RequestMsg.Body().GetObject();
- CbObjectView Header = Request["Header"sv].AsObjectView();
- std::string_view Method = Header["Method"].AsString();
- const uint64_t CorrelationId = Header["CorrelationId"].AsUInt64();
+ std::string_view Method = Request["Method"].AsString();
- if (Method != "TestHelloZen"sv)
+ if (Method != "SayHello"sv)
{
return false;
}
CbObjectWriter Response;
- Response.BeginObject("Header");
- Response << "CorrelationId"sv << CorrelationId;
- Response.EndObject();
Response.AddString("Result"sv, "Hello Friend!!");
- PublishMessage(SocketId, Response.Save());
+ WebSocketMessage ResponseMsg;
+ ResponseMsg.SetMessageType(WebSocketMessageType::kResponse);
+ ResponseMsg.SetCorrelationId(RequestMsg.CorrelationId());
+ ResponseMsg.SetSocketId(RequestMsg.SocketId());
+ ResponseMsg.SetBody(Response.Save());
+
+ SocketServer().SendResponse(std::move(ResponseMsg));
return true;
}