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

Ensure we can read the request body from any process

This commit is contained in:
Loïc Hoguin 2019-10-02 19:12:05 +02:00
parent 8f6ee9c186
commit 20660d7566
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 28 additions and 9 deletions

View file

@ -30,6 +30,16 @@ echo(<<"read_body">>, Req0, Opts) ->
Length = cowboy_req:body_length(Req1),
{ok, integer_to_binary(Length), Req1};
<<"/opts", _/bits>> -> cowboy_req:read_body(Req0, Opts);
<<"/spawn", _/bits>> ->
Parent = self(),
Pid = spawn_link(fun() ->
Parent ! {self(), cowboy_req:read_body(Req0)}
end),
receive
{Pid, Msg} -> Msg
after 5000 ->
error(timeout)
end;
_ -> cowboy_req:read_body(Req0)
end,
{ok, cowboy_req:reply(200, #{}, Body, Req), Opts};