Current section
Files
Jump to
Current section
Files
lib/util.ex
defmodule SsoLogin.Util do
@moduledoc """
模块内部使用的工具函数
"""
import Plug.Conn
def get_request_url(conn) do
get_header(conn, "x-forwarded-uri") || build_request_url(conn)
end
defp build_request_url(conn) do
protocal = get_header(conn, "x-forwarded-proto") || conn.scheme
host = get_header(conn, "host") || conn.host
url = "#{protocal}://#{host}#{conn.request_path}"
if String.length(conn.query_string) > 0 do
"#{url}?#{conn.query_string}"
else
url
end
end
defp get_header(conn, name) do
conn
|> get_req_header(name)
|> List.first()
end
end