mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Better error message when trying to reply twice
Also crash if trying to push after a reply was sent.
This commit is contained in:
parent
f0101ffe41
commit
906a7ffc3c
3 changed files with 71 additions and 9 deletions
|
@ -130,6 +130,10 @@ do(<<"inform2">>, Req0, Opts) ->
|
|||
<<"twice">> ->
|
||||
cowboy_req:inform(102, Req0),
|
||||
cowboy_req:inform(102, Req0);
|
||||
<<"after_reply">> ->
|
||||
ct_helper:ignore(cowboy_req, inform, 3),
|
||||
Req1 = cowboy_req:reply(200, Req0),
|
||||
cowboy_req:inform(102, Req1);
|
||||
Status ->
|
||||
cowboy_req:inform(binary_to_integer(Status), Req0)
|
||||
end,
|
||||
|
@ -146,6 +150,10 @@ do(<<"inform3">>, Req0, Opts) ->
|
|||
<<"twice">> ->
|
||||
cowboy_req:inform(102, Headers, Req0),
|
||||
cowboy_req:inform(102, Headers, Req0);
|
||||
<<"after_reply">> ->
|
||||
ct_helper:ignore(cowboy_req, inform, 3),
|
||||
Req1 = cowboy_req:reply(200, Req0),
|
||||
cowboy_req:inform(102, Headers, Req1);
|
||||
Status ->
|
||||
cowboy_req:inform(binary_to_integer(Status), Headers, Req0)
|
||||
end,
|
||||
|
@ -215,6 +223,13 @@ do(<<"stream_reply2">>, Req0, Opts) ->
|
|||
Req = cowboy_req:stream_reply(304, Req0),
|
||||
stream_body(Req),
|
||||
{ok, Req, Opts};
|
||||
<<"twice">> ->
|
||||
ct_helper:ignore(cowboy_req, stream_reply, 3),
|
||||
Req1 = cowboy_req:stream_reply(200, Req0),
|
||||
%% We will crash here so the body shouldn't be sent.
|
||||
Req = cowboy_req:stream_reply(200, Req1),
|
||||
stream_body(Req),
|
||||
{ok, Req, Opts};
|
||||
Status ->
|
||||
Req = cowboy_req:stream_reply(binary_to_integer(Status), Req0),
|
||||
stream_body(Req),
|
||||
|
@ -403,6 +418,11 @@ do(<<"push">>, Req, Opts) ->
|
|||
<<"qs">> ->
|
||||
cowboy_req:push("/static/style.css", #{<<"accept">> => <<"text/css">>}, Req,
|
||||
#{qs => <<"server=cowboy&version=2.0">>});
|
||||
<<"after_reply">> ->
|
||||
ct_helper:ignore(cowboy_req, push, 4),
|
||||
Req1 = cowboy_req:reply(200, Req),
|
||||
%% We will crash here so no need to worry about propagating Req1.
|
||||
cowboy_req:push("/static/style.css", #{<<"accept">> => <<"text/css">>}, Req1);
|
||||
_ ->
|
||||
cowboy_req:push("/static/style.css", #{<<"accept">> => <<"text/css">>}, Req),
|
||||
%% The text/plain mime is not defined by default, so a 406 will be returned.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue