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