Created
February 2, 2015 18:41
-
-
Save anonymous/3ce6914e4aa9f992d25c to your computer and use it in GitHub Desktop.
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
if get_req_header(conn, "https") == "on" or | |
get_req_header(conn, "x-forwarded-ssl") == "on" or | |
get_req_header(conn, "x-forwarded-scheme") == "https" or | |
(get_req_header(conn, "x-forwarded-proto") |> to_string |> String.split(",") |> Enum.at(0)) == "https" or | |
conn.scheme == :https do | |
"Secure Request" | |
else | |
"Request" | |
end |
chrismccord
commented
Feb 2, 2015
Option 2, overwrite conn.scheme
:
defmodule SecureRequest do
import Plug.Conn
def init(opts), do: opts
def call(conn, _) do
if get_req_header(conn, "https") == "on" or
get_req_header(conn, "x-forwarded-ssl") == "on" or
get_req_header(conn, "x-forwarded-scheme") == "https" or
proto_header(conn) == "https" or
conn.scheme == :https do
put_in(conn.scheme, :https)
else
put_in(conn.scheme, :http)
end
end
defp proto_header(conn) do
get_req_header(conn, "x-forwarded-proto") |> to_string |> String.split(",") |> Enum.at(0)
end
end
# router
pipeline :browser do
plug SecureRequest
end
# controller
def create(%Conn{scheme: :https}, params) do
end
def create(%Conn{scheme: :http}, params) do
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment