Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active August 23, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/42f596c31763ef4d49ed4a7962eb3ce9 to your computer and use it in GitHub Desktop.
Save henrik/42f596c31763ef4d49ed4a7962eb3ce9 to your computer and use it in GitHub Desktop.
Elixir Plug request_url function.
defmodule Plug.Conn.RequestURL do
def request_url(conn) do
Enum.join([
conn.scheme,
"://",
conn.host,
shown_port(conn.scheme, conn.port),
conn.request_path,
shown_qs(conn.query_string),
])
end
defp shown_port(:http, 80), do: ""
defp shown_port(:https, 443), do: ""
defp shown_port(_, port), do: ":#{port}"
defp shown_qs(""), do: ""
defp shown_qs(qs), do: "?#{qs}"
end
@henrik
Copy link
Author

henrik commented Aug 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment