From e26ebc985b882c38da50fb0104791a5f2c0f8522 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 8 Apr 2009 17:42:23 -0700 Subject: http11: handle "X-Forwarded-Proto: https" Pass "https" to "rack.url_scheme" if the X-Forwarded-Proto header matches "https". X-Forwarded-Proto is a semi-standard header that Ruby frameworks seem to respect; so we use that. We won't support ENV['HTTPS'] since that can only be set at start time and some app servers supporting https also support http. Currently, "rack.url_scheme" only allows "http" and "https", so we won't set anything else to avoid breaking Rack::Lint. --- test/unit/test_request.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb index dacbac0..5109c7b 100644 --- a/test/unit/test_request.rb +++ b/test/unit/test_request.rb @@ -55,10 +55,31 @@ class RequestTest < Test::Unit::TestCase assert_nothing_raised { res = @lint.call(env) } end + def test_x_forwarded_proto + res = env = nil + client = MockRequest.new("GET / HTTP/1.1\r\n" \ + "X-Forwarded-Proto: https\r\n" \ + "Host: foo\r\n\r\n") + assert_nothing_raised { env = @request.read(client) } + assert_equal "https", env['rack.url_scheme'] + assert_nothing_raised { res = @lint.call(env) } + end + + def test_x_forwarded_proto_invalid + res = env = nil + client = MockRequest.new("GET / HTTP/1.1\r\n" \ + "X-Forwarded-Proto: ftp\r\n" \ + "Host: foo\r\n\r\n") + assert_nothing_raised { env = @request.read(client) } + assert_equal "http", env['rack.url_scheme'] + assert_nothing_raised { res = @lint.call(env) } + end + def test_rack_lint_get client = MockRequest.new("GET / HTTP/1.1\r\nHost: foo\r\n\r\n") res = env = nil assert_nothing_raised { env = @request.read(client) } + assert_equal "http", env['rack.url_scheme'] assert_equal '666.666.666.666', env['REMOTE_ADDR'] assert_nothing_raised { res = @lint.call(env) } end -- cgit v1.2.3-24-ge0c7