0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add an undocumented stream_events function

I will test it on a private project before settling on it.
This commit is contained in:
Loïc Hoguin 2018-06-25 15:56:29 +02:00
parent f08f4610a0
commit b2b5e3a01a
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -80,7 +80,8 @@
-export([stream_reply/3]). -export([stream_reply/3]).
%% @todo stream_body/2 (nofin) %% @todo stream_body/2 (nofin)
-export([stream_body/3]). -export([stream_body/3]).
%% @todo stream_event/2,3 %% @todo stream_events/2 (nofin)
-export([stream_events/3]).
-export([stream_trailers/2]). -export([stream_trailers/2]).
-export([push/3]). -export([push/3]).
-export([push/4]). -export([push/4]).
@ -786,6 +787,13 @@ stream_body(Data, IsFin, #{pid := Pid, streamid := StreamID, has_sent_resp := he
Pid ! {{Pid, StreamID}, {data, IsFin, Data}}, Pid ! {{Pid, StreamID}, {data, IsFin, Data}},
ok. ok.
-spec stream_events(cow_sse:event() | [cow_sse:event()], fin | nofin, req()) -> ok.
stream_events(Event, IsFin, Req) when is_map(Event) ->
stream_events([Event], IsFin, Req);
stream_events(Events, IsFin, #{pid := Pid, streamid := StreamID, has_sent_resp := headers}) ->
Pid ! {{Pid, StreamID}, {data, IsFin, cow_sse:events(Events)}},
ok.
-spec stream_trailers(cowboy:http_headers(), req()) -> ok. -spec stream_trailers(cowboy:http_headers(), req()) -> ok.
stream_trailers(Trailers, #{pid := Pid, streamid := StreamID, has_sent_resp := headers}) -> stream_trailers(Trailers, #{pid := Pid, streamid := StreamID, has_sent_resp := headers}) ->
Pid ! {{Pid, StreamID}, {trailers, Trailers}}, Pid ! {{Pid, StreamID}, {trailers, Trailers}},