From 6c765101b1babe30b621a11dadbed37d28798ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 20 Nov 2017 12:13:57 +0100 Subject: Fix compression when trailers are sent --- src/cowboy_compress_h.erl | 8 ++++++-- 1 file 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]). -- cgit v1.2.3