use 303 for redirects from post for HTTP/1.1 (fixes ajax redirects in Internet Explorer 9)
This commit is contained in:
parent
f1b35074c5
commit
5a16e33f91
|
@ -113,7 +113,11 @@ module Sinatra
|
|||
|
||||
# Halt processing and redirect to the URI provided.
|
||||
def redirect(uri, *args)
|
||||
status 302
|
||||
if env['HTTP_VERSION'] == 'HTTP/1.1' and env["REQUEST_METHOD"] != 'GET'
|
||||
status 303
|
||||
else
|
||||
status 302
|
||||
end
|
||||
|
||||
# According to RFC 2616 section 14.30, "the field value consists of a
|
||||
# single absolute URI"
|
||||
|
|
|
@ -207,6 +207,22 @@ class HelpersTest < Test::Unit::TestCase
|
|||
assert_equal 'http://example.org:444/foo', response['Location']
|
||||
end
|
||||
|
||||
it 'uses 303 for post requests if request is HTTP 1.1' do
|
||||
mock_app { post('/') { redirect '/'} }
|
||||
post '/', {}, 'HTTP_VERSION' => 'HTTP/1.1'
|
||||
assert_equal 303, status
|
||||
assert_equal '', body
|
||||
assert_equal 'http://example.org/', response['Location']
|
||||
end
|
||||
|
||||
it 'uses 302 for post requests if request is HTTP 1.0' do
|
||||
mock_app { post('/') { redirect '/'} }
|
||||
post '/', {}, 'HTTP_VERSION' => 'HTTP/1.0'
|
||||
assert_equal 302, status
|
||||
assert_equal '', body
|
||||
assert_equal 'http://example.org/', response['Location']
|
||||
end
|
||||
|
||||
it 'works behind a reverse proxy' do
|
||||
mock_app do
|
||||
get '/' do
|
||||
|
|
Loading…
Reference in New Issue