From 20660d7566b63977e80f694724fee890d875ec1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 2 Oct 2019 19:12:05 +0200 Subject: Ensure we can read the request body from any process --- test/handlers/echo_h.erl | 10 ++++++++++ test/req_SUITE.erl | 6 ++++++ 2 files changed, 16 insertions(+) (limited to 'test') diff --git a/test/handlers/echo_h.erl b/test/handlers/echo_h.erl index ec37a66..7d0e75b 100644 --- a/test/handlers/echo_h.erl +++ b/test/handlers/echo_h.erl @@ -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}; diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl index eafabfe..72cc0ed 100644 --- a/test/req_SUITE.erl +++ b/test/req_SUITE.erl @@ -57,6 +57,7 @@ init_dispatch(Config) -> {"/opts/:key/timeout", echo_h, #{timeout => 1000, crash => true}}, {"/100-continue/:key", echo_h, []}, {"/full/:key", echo_h, []}, + {"/spawn/:key", echo_h, []}, {"/no/:key", echo_h, []}, {"/direct/:key/[...]", echo_h, []}, {"/:key/[...]", echo_h, []} @@ -488,6 +489,11 @@ do_read_body_timeout(Path, Body, Config) -> {response, _, 500, _} = gun:await(ConnPid, Ref), gun:close(ConnPid). +read_body_spawn(Config) -> + doc("Confirm we can use cowboy_req:read_body/1,2 from another process."), + <<"hello world!">> = do_body("POST", "/spawn/read_body", [], "hello world!", Config), + ok. + read_body_expect_100_continue(Config) -> doc("Request body with a 100-continue expect header."), do_read_body_expect_100_continue("/read_body", Config). -- cgit v1.2.3