Skip to content

Commit 9afa99f

Browse files
authored
Merge pull request #40 from polaon/handle-notifications-in-sse-server
Handle notifications in SSE server
2 parents 734b799 + be8bd9b commit 9afa99f

2 files changed

Lines changed: 333 additions & 159 deletions

File tree

src/server/sse_server.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,22 @@ bool SseServerWrapper::start()
511511
return;
512512
}
513513

514+
// JSON-RPC notifications (missing/null id) must not receive responses.
515+
const bool is_notification = !message.contains("id") || message["id"].is_null();
516+
if (is_notification)
517+
{
518+
try
519+
{
520+
(void)handler_(message); // process side effects only
521+
}
522+
catch (...)
523+
{
524+
// Ignore notification errors by design.
525+
}
526+
res.status = 202;
527+
return;
528+
}
529+
514530
// Normal request - process with handler
515531
auto response = handler_(message);
516532

0 commit comments

Comments
 (0)