Skip to content

Commit 26db484

Browse files
committed
Fix a deprecation warning in the Cowboy adapters
1 parent 82c58bf commit 26db484

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/plug/adapters/cowboy.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule Plug.Adapters.Cowboy do
4747
@doc false
4848
def args(scheme, plug, opts, cowboy_options) do
4949
{cowboy_options, non_keyword_options} =
50-
Enum.partition(cowboy_options, &is_tuple(&1) and tuple_size(&1) == 2)
50+
enum_split_with(cowboy_options, &(is_tuple(&1) and tuple_size(&1) == 2))
5151

5252
cowboy_options
5353
|> Keyword.put_new(:max_connections, 16_384)
@@ -334,4 +334,9 @@ defmodule Plug.Adapters.Cowboy do
334334
defp fail(message) do
335335
raise ArgumentError, message: "could not start Cowboy adapter, " <> message
336336
end
337+
338+
# TODO: Remove once we depend on Elixir ~> 1.4.
339+
Code.ensure_loaded(Enum)
340+
split_with = if function_exported?(Enum, :split_with, 2), do: :split_with, else: :partition
341+
defp enum_split_with(enum, fun), do: apply(Enum, unquote(split_with), [enum, fun])
337342
end

lib/plug/adapters/cowboy2.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule Plug.Adapters.Cowboy2 do
4343
@doc false
4444
def args(scheme, plug, opts, cowboy_options) do
4545
{cowboy_options, non_keyword_options} =
46-
Enum.partition(cowboy_options, &(is_tuple(&1) and tuple_size(&1) == 2))
46+
enum_split_with(cowboy_options, &(is_tuple(&1) and tuple_size(&1) == 2))
4747

4848
cowboy_options
4949
|> Keyword.put_new(:max_connections, 16_384)
@@ -332,4 +332,9 @@ defmodule Plug.Adapters.Cowboy2 do
332332
defp fail(message) do
333333
raise ArgumentError, message: "could not start Cowboy2 adapter, " <> message
334334
end
335+
336+
# TODO: Remove once we depend on Elixir ~> 1.4.
337+
Code.ensure_loaded(Enum)
338+
split_with = if function_exported?(Enum, :split_with, 2), do: :split_with, else: :partition
339+
defp enum_split_with(enum, fun), do: apply(Enum, unquote(split_with), [enum, fun])
335340
end

0 commit comments

Comments
 (0)