Last active
June 16, 2016 07:10
-
-
Save davoclavo/262a8c3b18c73b36770ef7f17f172dae to your computer and use it in GitHub Desktop.
Plug.Conn.to_uri
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 do | |
def to_uri(conn) do | |
query = case conn.query_string do | |
"" -> nil | |
query -> query | |
end | |
%URI{ | |
scheme: conn.scheme |> to_string, | |
host: conn.host, | |
port: conn.port, | |
path: conn.request_path, | |
query: query | |
# userinfo: "user:password" # Is Authorization always in the headers, or is that a browser thing? | |
# fragment: "some url #fragment" | |
# authority: "user:[email protected]:80" | |
} | |
end | |
end | |
conn | |
|> Plug.Conn.to_uri | |
|> URI.to_string | |
# https://example.com:443/path?query=lala |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment