diff --git a/falcon.gemspec b/falcon.gemspec index 7ce5b8c9..c769837d 100644 --- a/falcon.gemspec +++ b/falcon.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| spec.add_dependency "async", "~> 1.13" spec.add_dependency "async-io", "~> 1.22" - spec.add_dependency "async-http", "~> 0.48.0" + spec.add_dependency "async-http" spec.add_dependency "async-container", "~> 0.14.0" spec.add_dependency "rack", ">= 1.0" diff --git a/lib/falcon/adapters/rack.rb b/lib/falcon/adapters/rack.rb index f803808a..12ce4356 100644 --- a/lib/falcon/adapters/rack.rb +++ b/lib/falcon/adapters/rack.rb @@ -105,6 +105,7 @@ def unwrap_request(request, env) # https://tools.ietf.org/html/rfc7239#section-5.4 # https://github.com/rack/rack/issues/1310 env[HTTP_X_FORWARDED_PROTO] ||= request.scheme + env[RACK_URL_SCHEME] = env[HTTP_X_FORWARDED_PROTO] if remote_address = request.remote_address env[REMOTE_ADDR] = remote_address.ip_address if remote_address.ip? @@ -157,7 +158,7 @@ def call(request) } self.unwrap_request(request, env) - + if request.push? env[RACK_EARLY_HINTS] = EarlyHints.new(request) end diff --git a/spec/falcon/adapters/rack_spec.rb b/spec/falcon/adapters/rack_spec.rb index f2a45e5f..8b467006 100644 --- a/spec/falcon/adapters/rack_spec.rb +++ b/spec/falcon/adapters/rack_spec.rb @@ -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