Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit 40d2b7c

Browse files
committed
Replace compress option by cowboy_compress_h
Deprecated from cowboy 2.0 Note: Only streams > 300 bytes are compressed [#159994213]
1 parent 600a709 commit 40d2b7c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/rabbit_web_dispatch_sup.erl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ ensure_listener(Listener) ->
4040
ProtoOptsMap = maps:from_list(ProtoOpts),
4141
rabbit_log:debug("Starting HTTP[S] listener with transport ~s, options ~p and protocol options ~p",
4242
[Transport, TransportOpts, ProtoOptsMap]),
43+
StreamHandlers = stream_handlers_config(ProtoOpts),
4344
CowboyOptsMap =
4445
maps:merge(#{env =>
4546
#{rabbit_listener => Listener},
4647
middlewares =>
4748
[rabbit_cowboy_middleware, cowboy_router, cowboy_handler],
48-
stream_handlers =>
49-
[rabbit_cowboy_stream_h, cowboy_stream_h]},
49+
stream_handlers => StreamHandlers},
5050
ProtoOptsMap),
5151
Child = ranch:child_spec(name(Listener), 100,
5252
Transport, TransportOpts,
@@ -122,11 +122,15 @@ transport_config(Options0) ->
122122
end.
123123

124124
protocol_config(Options) ->
125-
ProtoOpts = proplists:get_value(cowboy_opts, Options, []),
126-
%% Compress responses by default.
127-
case lists:keyfind(compress, 1, ProtoOpts) of
128-
false -> [{compress, true}|ProtoOpts];
129-
_ -> ProtoOpts
125+
proplists:get_value(cowboy_opts, Options, []).
126+
127+
stream_handlers_config(Options) ->
128+
case lists:keyfind(compress, 1, Options) of
129+
{compress, false} -> [rabbit_cowboy_stream_h, cowboy_stream_h];
130+
%% Compress by default. Since 2.0 the compress option in cowboys
131+
%% has been replaced by the cowboy_compress_h handler
132+
%% Compress is not applied if data < 300 bytes
133+
_ -> [rabbit_cowboy_stream_h, cowboy_compress_h, cowboy_stream_h]
130134
end.
131135

132136
check_error(Listener, Error) ->

0 commit comments

Comments
 (0)