diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-08 17:42:23 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-08 17:42:23 -0700 |
commit | e26ebc985b882c38da50fb0104791a5f2c0f8522 (patch) | |
tree | aed3ecdde023b3809c7ee9de6c8e8ed63fe1f8b0 /test/unit/test_request.rb | |
parent | 9625ad39b73d3d1443ff097e9113d1ec9c9d5f00 (diff) | |
download | unicorn-e26ebc985b882c38da50fb0104791a5f2c0f8522.tar.gz |
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.
Diffstat (limited to 'test/unit/test_request.rb')
-rw-r--r-- | test/unit/test_request.rb | 21 |
1 files changed, 21 insertions, 0 deletions
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 |