RefInspector Plug v0.1.0 RefInspector.Plug View Source
RefInspector Plug
Usage
After ensuring :ref_inspector
is configured you need to add the plug:
defmodule MyRouter do
use Plug.Router
# ...
plug RefInspector.Plug
# ...
plug :match
plug :dispatch
end
Depending on how you are using plugs the actual location may vary. Please consult your frameworks documentation to find the proper place.
Once setup the connection will be automatically enriched with the results of
a lookup based on the connections referer
header:
defmodule MyRouter do
get "/" do
case RefInspector.Plug.get_result(conn) do
nil -> send_resp(conn, 500, "No lookup done")
%{referer: ""} -> send_resp(conn, 404, "Missing referer")
%{source: :unknown} -> send_resp(conn, 200, "Unknown referer")
%{source: source} -> send_resp(conn, 200, "Client source: " <> source)
end
end
end
Link to this section Summary
Functions
Callback implementation for Plug.call/2
Returns the lookup result from the connection
Callback implementation for Plug.init/1
Link to this section Functions
Link to this function
call(conn, opts) View Source
Callback implementation for Plug.call/2
.
Link to this function
get_result(conn)
View Source
get_result(conn)
View Source
get_result(Plug.Conn.t()) :: nil | RefInspector.Result.t()
get_result(Plug.Conn.t()) :: nil | RefInspector.Result.t()
Returns the lookup result from the connection.
Link to this function
init(opts) View Source
Callback implementation for Plug.init/1
.