aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-04-16 15:18:53 +0200
committerLoïc Hoguin <[email protected]>2020-04-16 15:18:53 +0200
commita3308b8e4771eff64011bc683c7bdd94b79ceff3 (patch)
tree3c4f9003f613deff6f890c0f8ca20de085fa18ad
parent0a373761d881aed81272e3ebc7778626bd4968ea (diff)
downloadgun-a3308b8e4771eff64011bc683c7bdd94b79ceff3.tar.gz
gun-a3308b8e4771eff64011bc683c7bdd94b79ceff3.tar.bz2
gun-a3308b8e4771eff64011bc683c7bdd94b79ceff3.zip
Empty the commands queue when returning
-rw-r--r--src/gun_http.erl12
-rw-r--r--src/gun_http2.erl12
2 files changed, 18 insertions, 6 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index dd48c42..b5ad751 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -123,11 +123,17 @@ switch_transport(Transport, Socket, State) ->
%% This function is called before returning from handle/4.
handle_ret(CommandOrCommands, #http_state{commands_queue=[]}) ->
- CommandOrCommands;
+ empty_commands_queue(CommandOrCommands);
handle_ret(Commands, #http_state{commands_queue=Queue}) when is_list(Commands) ->
- lists:reverse(Queue, Commands);
+ lists:reverse(Queue, empty_commands_queue(Commands));
handle_ret(Command, #http_state{commands_queue=Queue}) ->
- lists:reverse([Command|Queue]).
+ lists:reverse([empty_commands_queue(Command)|Queue]).
+
+empty_commands_queue([{state, State}|Tail]) -> [{state, State#http_state{commands_queue=[]}}|Tail];
+empty_commands_queue([Command|Tail]) -> [Command|empty_commands_queue(Tail)];
+empty_commands_queue([]) -> [];
+empty_commands_queue({state, State}) -> {state, State#http_state{commands_queue=[]}};
+empty_commands_queue(Command) -> Command.
%% Stop looping when we got no more data.
handle(<<>>, State, _, EvHandlerState) ->
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 9edabaa..fef1096 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -153,11 +153,17 @@ switch_transport(Transport, Socket, State) ->
%% This function is called before returning from handle/4.
handle_ret(CommandOrCommands, #http2_state{commands_queue=[]}) ->
- CommandOrCommands;
+ empty_commands_queue(CommandOrCommands);
handle_ret(Commands, #http2_state{commands_queue=Queue}) when is_list(Commands) ->
- lists:reverse(Queue, Commands);
+ lists:reverse(Queue, empty_commands_queue(Commands));
handle_ret(Command, #http2_state{commands_queue=Queue}) ->
- lists:reverse([Command|Queue]).
+ lists:reverse([empty_commands_queue(Command)|Queue]).
+
+empty_commands_queue([{state, State}|Tail]) -> [{state, State#http2_state{commands_queue=[]}}|Tail];
+empty_commands_queue([Command|Tail]) -> [Command|empty_commands_queue(Tail)];
+empty_commands_queue([]) -> [];
+empty_commands_queue({state, State}) -> {state, State#http2_state{commands_queue=[]}};
+empty_commands_queue(Command) -> Command.
handle(Data, State=#http2_state{buffer=Buffer}, EvHandler, EvHandlerState) ->
parse(<< Buffer/binary, Data/binary >>, State#http2_state{buffer= <<>>},