This commit is contained in:
ochko 2012-11-30 15:14:49 +09:00
Родитель 90025f4eec
Коммит b1bc0f2388
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -15,6 +15,7 @@ module Rack
def initialize(app, options={})
default_options = {
:redirect_to => nil,
:redirect_code => nil,
:strict => false,
:mixed => false,
:hsts => nil,
@ -84,7 +85,7 @@ module Rack
def redirect_to(location)
body = "<html><body>You are being <a href=\"#{location}\">redirected</a>.</body></html>"
[301, { 'Content-Type' => 'text/html', 'Location' => location }, [body]]
[@options[:redirect_code] || 301, { 'Content-Type' => 'text/html', 'Location' => location }, [body]]
end
def ssl_request?
@ -100,7 +101,7 @@ module Rack
# Fixed in rack >= 1.3
def current_scheme
if @request.env['HTTPS'] == 'on'
if @request.env['HTTPS'] == 'on' || @request.env['HTTP_X_SSL_REQUEST'] == 'on'
'https'
elsif @request.env['HTTP_X_FORWARDED_PROTO']
@request.env['HTTP_X_FORWARDED_PROTO'].split(',')[0]

Просмотреть файл

@ -123,6 +123,16 @@ class TestRackSslEnforcer < Test::Unit::TestCase
end
end
context ':redirect_code' do
setup { mock_app :redirect_code => 302 }
should 'redirect to HTTPS and keep params' do
get 'http://www.example.org/admin/account'
assert_equal 302, last_response.status
assert_equal 'https://www.example.org/admin/account', last_response.location
end
end
context ':only (Regex)' do
setup { mock_app :only => /^\/admin/ }