From a3308b8e4771eff64011bc683c7bdd94b79ceff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 16 Apr 2020 15:18:53 +0200 Subject: Empty the commands queue when returning --- src/gun_http.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/gun_http.erl') 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) -> -- cgit v1.2.3