Skip to content

Commit 8ea2a34

Browse files
committed
Add non-deprecated adapter back with deprecations
1 parent 840a7fe commit 8ea2a34

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

lib/plug/adapters/cowboy.ex

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defmodule Plug.Adapters.Cowboy do
2+
@moduledoc false
3+
4+
@doc false
5+
@deprecated "Use Plug.Cowboy.http/3 instead"
6+
def http(plug, opts, cowboy_options \\ []) do
7+
unless using_plug_cowboy?(), do: warn_and_raise()
8+
Plug.Cowboy.http(plug, opts, cowboy_options)
9+
end
10+
11+
@doc false
12+
@deprecated "Use Plug.Cowboy.https/3 instead"
13+
def https(plug, opts, cowboy_options \\ []) do
14+
unless using_plug_cowboy?(), do: warn_and_raise()
15+
Plug.Cowboy.https(plug, opts, cowboy_options)
16+
end
17+
18+
@doc false
19+
@deprecated "Use Plug.Cowboy.shutdown/1 instead"
20+
def shutdown(ref) do
21+
unless using_plug_cowboy?(), do: warn_and_raise()
22+
Plug.Cowboy.shutdown(ref)
23+
end
24+
25+
@doc false
26+
@deprecated "Use Plug.Cowboy.child_spec/4 instead"
27+
def child_spec(scheme, plug, opts, cowboy_options \\ []) do
28+
unless using_plug_cowboy?(), do: warn_and_raise()
29+
Plug.Cowboy.child_spec(scheme, plug, opts, cowboy_options)
30+
end
31+
32+
@doc false
33+
@deprecated "Use Plug.Cowboy.child_spec/1 instead"
34+
def child_spec(opts) do
35+
unless using_plug_cowboy?(), do: warn_and_raise()
36+
Plug.Cowboy.child_spec(opts)
37+
end
38+
39+
defp using_plug_cowboy?() do
40+
Code.ensure_loaded?(Plug.Cowboy)
41+
end
42+
43+
defp warn_and_raise() do
44+
error = """
45+
please add the following dependency to your mix.exs:
46+
{:plug_cowboy, "~> 1.0"}
47+
This dependency is required by Plug.Adapters.Cowboy
48+
which you may be using directly or indirectly.
49+
Note you no longer need to depend on :cowboy directly.
50+
"""
51+
52+
IO.warn(error, [])
53+
:erlang.raise(:exit, "plug_cowboy dependency missing", [])
54+
end
55+
end

0 commit comments

Comments
 (0)