From c5ffa933442461deae68efae51a8e2c096afae82 Mon Sep 17 00:00:00 2001 From: Andy Lindeman Date: Mon, 24 Mar 2014 22:08:15 -0400 Subject: [PATCH] request.scheme supports multiple x-http-forwarded-proto values --- lib/rack/request.rb | 2 +- test/spec_request.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 07627ddbd..380a2e7aa 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -97,7 +97,7 @@ def port elsif @env.has_key?("HTTP_X_FORWARDED_HOST") DEFAULT_PORTS[scheme] elsif @env.has_key?("HTTP_X_FORWARDED_PROTO") - DEFAULT_PORTS[@env['HTTP_X_FORWARDED_PROTO']] + DEFAULT_PORTS[@env['HTTP_X_FORWARDED_PROTO'].split(',')[0]] else @env["SERVER_PORT"].to_i end diff --git a/test/spec_request.rb b/test/spec_request.rb index f5210e570..3c35ca9a6 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -96,7 +96,10 @@ req = Rack::Request.new \ Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost", "HTTP_X_FORWARDED_PROTO" => "https", "SERVER_PORT" => "80") + req.port.should.equal 443 + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "localhost", "HTTP_X_FORWARDED_PROTO" => "https,https", "SERVER_PORT" => "80") req.port.should.equal 443 end