Why wouldn’t it make sense? (I haven’t really explored this area with zig / lowlevel programming yet)
From how I read the question it seemed to me like these notifications might be very rare, from looking at the project you linked, it says that it starts a thread for handling SSE:
Server Side Events can be enabled by calling res.startEventStream(). This method takes an arbitrary context and a function pointer. The provided function will be executed in a new thread, receiving the provided context and an std.net.Stream.
It also says that it is an HTTP/1.1 server, looking at this Using server-sent events - Web APIs | MDN it comes with a warning (which I don’t know whether it would matter in this case):
Warning: When not used over HTTP/2, SSE suffers from a limitation to the maximum number of open connections, which can be especially painful when opening multiple tabs, as the limit is per browser and is set to a very low number (6). The issue has been marked as “Won’t fix” in Chrome and Firefox. This limit is per browser + domain, which means that you can open 6 SSE connections across all of the tabs to www.example1.com
and another 6 SSE connections to www.example2.com
(per Stack Overflow). When using HTTP/2, the maximum number of simultaneous HTTP streams is negotiated between the server and the client (defaults to 100).
I haven’t worked with SSE so I am not sure about it and the details.
But if I was trying to use it and had the case where I rarely (like every few minutes) want to send a notification to a client, then I would want some kind of lightweight connection, where a single thread can manage multiple connections, because the majority of time those connections aren’t used and it would be a waste to have a thread for every single connection. The part I don’t know is whether that can be done easily.
If I tried I would probably try to use libxev.
libxev has:
Timers, TCP, UDP, Files, Processes. High-level platform-agnostic APIs for interacting with timers, TCP/UDP sockets, files, processes, and more.
So I would think that TCP/UDP support would be enough to use TLS/HTTP on top of that, I think somebody could create a library that pairs well with libxev to use its TCP/UDP support and then implements support for sending HTTP things over that, without the user having to worry about the details, but I don’t know whether somebody has already created that.
I picked up the sentiment of not running Zig servers directly exposed to the internet but instead running them behind something like nginx, but I don’t know where exactly that came from and I am not sure whether this was mostly connected to older posts / advice to not run std.http.Server (whether there have been newer projects/developments that aim at directly creating a production ready server written in Zig).
While http.zig looks good (without trying it), the fact that browsers limit numbers of SSE connections when not using a HTTP/2 connection and that it sounds as if it creates a thread for every SSE connection sounds bad (but maybe the description is just bad and it actually uses an event-loop/thread pool?).
To me the most practical approach would seem to be to give http.zig
a chance and I would probably try to use websockets instead of SSE to avoid the issue of having to deal with the limited number of connections.
All of this is from somebody who hasn’t done a lot of web programming the last years (but eventually I will try to use Zig for this when I have a project that goes beyond static sites).