aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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= <<>>},