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

Fix HTTP/1.1 bug when a flow command is returned after fin

This resulted in a badarith error due to the current flow being
set to infinity when the body has been fully read. A test case
has been added reproducing the issue.
This commit is contained in:
Loïc Hoguin 2020-02-07 11:32:15 +01:00
parent 47ecfd7318
commit 8fc3da2fc3
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 20 additions and 0 deletions

View file

@ -34,6 +34,8 @@ init_commands(_, _, #state{test=crash_in_terminate}) ->
[{response, 200, #{<<"content-length">> => <<"12">>}, <<"Hello world!">>}, stop];
init_commands(_, _, #state{test=crash_in_early_error}) ->
error(crash);
init_commands(_, _, #state{test=flow_after_body_fully_read}) ->
[];
init_commands(_, _, #state{test=set_options_ignore_unknown}) ->
[
{set_options, #{unknown_options => true}},
@ -81,6 +83,8 @@ init_process(TrapExit, #state{pid=Pid}) ->
data(_, _, _, #state{test=crash_in_data}) ->
error(crash);
data(_, fin, <<"Hello world!">>, State=#state{test=flow_after_body_fully_read}) ->
{[{flow, 12}, {response, 200, #{}, <<"{}">>}], State};
data(StreamID, IsFin, Data, State=#state{pid=Pid}) ->
Pid ! {Pid, self(), data, StreamID, IsFin, Data, State},
{[], State}.

View file

@ -282,6 +282,19 @@ early_error_stream_error_reason(Config) ->
{response, fin, Status, _} = gun:await(ConnPid, Ref),
ok.
flow_after_body_fully_read(Config) ->
doc("A flow command may be returned even after the body was read fully."),
Self = self(),
ConnPid = gun_open(Config),
Ref = gun:post(ConnPid, "/long_polling", [
{<<"x-test-case">>, <<"flow_after_body_fully_read">>},
{<<"x-test-pid">>, pid_to_list(Self)}
], <<"Hello world!">>),
%% Receive a 200 response, sent after the second flow command,
%% confirming that the flow command was accepted.
{response, _, 200, _} = gun:await(ConnPid, Ref),
ok.
set_options_ignore_unknown(Config) ->
doc("Confirm that unknown options are ignored when using the set_options commands."),
Self = self(),