@@ -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
124124protocol_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
132136check_error (Listener , Error ) ->
0 commit comments