Browse Source

Fix compression when trailers are sent

Loïc Hoguin 7 years ago
parent
commit
6c765101b1
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/cowboy_compress_h.erl

+ 6 - 2
src/cowboy_compress_h.erl

@@ -128,8 +128,12 @@ fold([Response0={headers, _, Headers}|Tail], State0, Acc) ->
 fold([Data0={data, _, _}|Tail], State0=#state{compress=gzip}, Acc) ->
 	{Data, State} = gzip_data(Data0, State0),
 	fold(Tail, State, [Data|Acc]);
-%% Otherwise, we either have an unrelated command, or a data command
-%% with compression disabled.
+%% When trailers are sent we need to end the compression.
+%% This results in an extra data command being sent.
+fold([Trailers={trailers, _}|Tail], State0=#state{compress=gzip}, Acc) ->
+	{{data, fin, Data}, State} = gzip_data({data, fin, <<>>}, State0),
+	fold(Tail, State, [Trailers, {data, nofin, Data}|Acc]);
+%% Otherwise, we have an unrelated command or compression is disabled.
 fold([Command|Tail], State, Acc) ->
 	fold(Tail, State, [Command|Acc]).