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