Last active
August 23, 2017 20:09
-
-
Save henrik/42f596c31763ef4d49ed4a7962eb3ce9 to your computer and use it in GitHub Desktop.
Elixir Plug request_url function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Became: elixir-plug/plug#588