mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Ensure we can stream the response body from any process
This commit is contained in:
parent
20660d7566
commit
eaa052616f
4 changed files with 38 additions and 9 deletions
|
@ -247,6 +247,21 @@ do(<<"stream_body">>, Req0, Opts) ->
|
|||
cowboy_req:stream_body(<<"Hello! ">>, nofin, Req),
|
||||
cowboy_req:stream_body({sendfile, 0, AppSize, AppFile}, fin, Req),
|
||||
{ok, Req, Opts};
|
||||
<<"spawn">> ->
|
||||
Req = cowboy_req:stream_reply(200, Req0),
|
||||
Parent = self(),
|
||||
Pid = spawn(fun() ->
|
||||
cowboy_req:stream_body(<<"Hello ">>, nofin, Req),
|
||||
cowboy_req:stream_body(<<"world">>, nofin, Req),
|
||||
cowboy_req:stream_body(<<"!">>, fin, Req),
|
||||
Parent ! {self(), ok}
|
||||
end),
|
||||
receive
|
||||
{Pid, ok} -> ok
|
||||
after 5000 ->
|
||||
error(timeout)
|
||||
end,
|
||||
{ok, Req, Opts};
|
||||
_ ->
|
||||
%% Call stream_body without initiating streaming.
|
||||
cowboy_req:stream_body(<<0:800000>>, fin, Req0),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue