aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-11-20 12:13:57 +0100
committerLoïc Hoguin <[email protected]>2017-11-20 12:13:57 +0100
commit6c765101b1babe30b621a11dadbed37d28798ec5 (patch)
tree506138f8481be8af0fa026539b62aedecbf3d8c1 /src
parentecb2a735efc9837774eb18d491781d21c582dd5e (diff)
downloadcowboy-6c765101b1babe30b621a11dadbed37d28798ec5.tar.gz
cowboy-6c765101b1babe30b621a11dadbed37d28798ec5.tar.bz2
cowboy-6c765101b1babe30b621a11dadbed37d28798ec5.zip
Fix compression when trailers are sent
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_compress_h.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cowboy_compress_h.erl b/src/cowboy_compress_h.erl
index 9c2ae34..9dcb805 100644
--- a/src/cowboy_compress_h.erl
+++ b/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]).