Skip to content

Commit

Permalink
add get_baseurl_from_conn/1 clause to match x-forwarded-proto req_hea…
Browse files Browse the repository at this point in the history
…der for github.com//issues/94
  • Loading branch information
nelsonic committed May 16, 2023
1 parent efba82a commit a5ffa1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/elixir_auth_google.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ defmodule ElixirAuthGoogle do
"#{Atom.to_string(s)}://#{h}:#{p}"
end

def get_baseurl_from_conn(%{req_headers: r, host: h}) do
"#{Map.get(r, "x-forwarded-proto")}://#{h}"
end

def get_baseurl_from_conn(%{host: h, scheme: s}) do
"#{Atom.to_string(s)}://#{h}"
end
Expand Down
13 changes: 13 additions & 0 deletions test/elixir_auth_google_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ defmodule ElixirAuthGoogleTest do

import Mock

test "get_baseurl_from_conn(conn) x-forwarded-proto header for https #94" do
conn = %{
host: "gcal.fly.dev",
port: 80,
scheme: :http,
req_headers: %{
"x-forwarded-proto" => "https"
}
}

assert ElixirAuthGoogle.get_baseurl_from_conn(conn) == "https://gcal.fly.dev"
end

test "get_baseurl_from_conn(conn) detects the URL based on conn.host HTTP" do
conn = %{
host: "localhost",
Expand Down

0 comments on commit a5ffa1e

Please sign in to comment.