aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_compress_h.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_compress_h.erl')
-rw-r--r--src/cowboy_compress_h.erl19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/cowboy_compress_h.erl b/src/cowboy_compress_h.erl
index bd3df42..95c49d3 100644
--- a/src/cowboy_compress_h.erl
+++ b/src/cowboy_compress_h.erl
@@ -34,10 +34,7 @@
init(StreamID, Req, Opts) ->
State0 = check_req(Req),
CompressThreshold = maps:get(compress_threshold, Opts, 300),
- DeflateFlush = case maps:get(compress_buffering, Opts, false) of
- false -> sync;
- true -> none
- end,
+ DeflateFlush = buffering_to_zflush(maps:get(compress_buffering, Opts, false)),
{Commands0, Next} = cowboy_stream:init(StreamID, Req, Opts),
fold(Commands0, State0#state{next=Next,
threshold=CompressThreshold,
@@ -143,10 +140,24 @@ fold([Data0={data, _, _}|Tail], State0=#state{compress=gzip}, Acc) ->
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]);
+%% All the options from this handler can be updated for the current stream.
+fold([{set_options, Opts}|Tail], State=#state{
+ threshold=CompressThreshold0, deflate_flush=DeflateFlush0}, Acc) ->
+ CompressThreshold = maps:get(compress_threshold, Opts, CompressThreshold0),
+ DeflateFlush = case Opts of
+ #{compress_buffering := CompressBuffering} ->
+ buffering_to_zflush(CompressBuffering);
+ _ ->
+ DeflateFlush0
+ end,
+ fold(Tail, State#state{threshold=CompressThreshold, deflate_flush=DeflateFlush}, Acc);
%% Otherwise, we have an unrelated command or compression is disabled.
fold([Command|Tail], State, Acc) ->
fold(Tail, State, [Command|Acc]).
+buffering_to_zflush(true) -> none;
+buffering_to_zflush(false) -> sync.
+
gzip_response({response, Status, Headers, Body}, State) ->
%% We can't call zlib:gzip/1 because it does an
%% iolist_to_binary(GzBody) at the end to return