Skip to content

Commit

Permalink
Respect X-Forwarded-Proto headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jellybob committed Nov 12, 2019
1 parent 52e57c0 commit ad0c43e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/falcon/adapters/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def unwrap_request(request, env)
def call(request)
request_path, query_string = request.path.split('?', 2)
server_name, server_port = (request.authority || '').split(':', 2)

unless request.headers["x-forwarded-proto"].nil?
request.scheme = request.headers["x-forwarded-proto"].first
end

env = {
RACK_VERSION => [2, 0, 0],
Expand Down
22 changes: 22 additions & 0 deletions spec/falcon/adapters/rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@
end
end

context "rack.url_scheme" do
include_context Falcon::Server
let(:protocol) {Async::HTTP::Protocol::HTTP1}

let(:app) do
lambda do |env|
[200, {}, ["Scheme: #{env['rack.url_scheme'].inspect}"]]
end
end

it 'defaults to http' do
response = client.get('/')

expect(response.read).to be == 'Scheme: "http"'
end

it 'responses X-Forwarded-Proto headers' do
response = client.get('/', [["X-Forwarded-Proto", "https"]])

expect(response.read).to be == 'Scheme: "https"'
end
end
context "early hints" do
it_behaves_like Falcon::Adapters::EarlyHints
end
Expand Down

0 comments on commit ad0c43e

Please sign in to comment.