@@ -53,7 +53,6 @@ defmodule Plug.Cowboy do
53
53
{ cowboy_options , non_keyword_options } = Enum . split_with ( cowboy_options , & match? ( { _ , _ } , & 1 ) )
54
54
55
55
cowboy_options
56
- |> set_compress ( )
57
56
|> normalize_cowboy_options ( scheme )
58
57
|> to_args ( scheme , plug , plug_opts , non_keyword_options )
59
58
end
@@ -205,27 +204,6 @@ defmodule Plug.Cowboy do
205
204
apply ( :cowboy , start , args ( scheme , plug , opts , cowboy_options ) )
206
205
end
207
206
208
- @ default_stream_handlers [ Plug.Cowboy.Stream ]
209
-
210
- defp set_compress ( cowboy_options ) do
211
- compress = Keyword . get ( cowboy_options , :compress )
212
- stream_handlers = Keyword . get ( cowboy_options , :stream_handlers )
213
-
214
- case { compress , stream_handlers } do
215
- { true , nil } ->
216
- Keyword . put_new ( cowboy_options , :stream_handlers , [
217
- :cowboy_compress_h | @ default_stream_handlers
218
- ] )
219
-
220
- { true , _ } ->
221
- raise "cannot set both compress and stream_handlers at once. " <>
222
- "If you wish to set compress, please add `:cowboy_compress_h` to your stream handlers."
223
-
224
- _ ->
225
- cowboy_options
226
- end
227
- end
228
-
229
207
defp normalize_cowboy_options ( cowboy_options , :http ) do
230
208
Keyword . put_new ( cowboy_options , :port , 4000 )
231
209
end
@@ -249,7 +227,7 @@ defmodule Plug.Cowboy do
249
227
dispatch = :cowboy_router . compile ( dispatch || dispatch_for ( plug , plug_opts ) )
250
228
{ extra_options , opts } = Keyword . split ( opts , @ protocol_options )
251
229
252
- extra_options = Keyword . put_new ( extra_options , :stream_handlers , @ default_stream_handlers )
230
+ extra_options = set_stream_handlers ( extra_options )
253
231
protocol_and_extra_options = :maps . from_list ( protocol_options ++ extra_options )
254
232
protocol_options = Map . merge ( % { env: % { dispatch: dispatch } } , protocol_and_extra_options )
255
233
{ transport_options , socket_options } = Keyword . pop ( opts , :transport_options , [ ] )
@@ -280,6 +258,28 @@ defmodule Plug.Cowboy do
280
258
[ ref || build_ref ( plug , scheme ) , transport_options , protocol_options ]
281
259
end
282
260
261
+ @ default_stream_handlers [ Plug.Cowboy.Stream ]
262
+
263
+ defp set_stream_handlers ( opts ) do
264
+ compress = Keyword . get ( opts , :compress )
265
+ stream_handlers = Keyword . get ( opts , :stream_handlers )
266
+
267
+ case { compress , stream_handlers } do
268
+ { true , nil } ->
269
+ Keyword . put_new ( opts , :stream_handlers , [ :cowboy_compress_h | @ default_stream_handlers ] )
270
+
271
+ { true , _ } ->
272
+ raise "cannot set both compress and stream_handlers at once. " <>
273
+ "If you wish to set compress, please add `:cowboy_compress_h` to your stream handlers."
274
+
275
+ { _ , nil } ->
276
+ Keyword . put_new ( opts , :stream_handlers , @ default_stream_handlers )
277
+
278
+ { _ , _ } ->
279
+ opts
280
+ end
281
+ end
282
+
283
283
defp build_ref ( plug , scheme ) do
284
284
Module . concat ( plug , scheme |> to_string |> String . upcase ( ) )
285
285
end
0 commit comments