use status code 303 for redirects
This commit is contained in:
parent
b3942697a6
commit
c0eb84faa6
2
CHANGES
2
CHANGES
|
@ -42,6 +42,8 @@
|
||||||
|
|
||||||
* Improved error handling. (cactus, Konstantin Haase)
|
* Improved error handling. (cactus, Konstantin Haase)
|
||||||
|
|
||||||
|
* Use 303 instead of 302 for redirects. (Konstantin Haase)
|
||||||
|
|
||||||
* Skip missing template engines in tests correctly. (cactus)
|
* Skip missing template engines in tests correctly. (cactus)
|
||||||
|
|
||||||
* Sinatra now ships with a Gemfile for development dependencies, since it eases
|
* Sinatra now ships with a Gemfile for development dependencies, since it eases
|
||||||
|
|
|
@ -95,7 +95,9 @@ module Sinatra
|
||||||
|
|
||||||
# Halt processing and redirect to the URI provided.
|
# Halt processing and redirect to the URI provided.
|
||||||
def redirect(uri, *args)
|
def redirect(uri, *args)
|
||||||
status 302
|
# Browsers treat 302 like 303, even though it should rather be handled
|
||||||
|
# like 307. To show our good will, we use 303.
|
||||||
|
status 303
|
||||||
|
|
||||||
# According to RFC 2616 section 14.30, "the field value consists of a
|
# According to RFC 2616 section 14.30, "the field value consists of a
|
||||||
# single absolute URI"
|
# single absolute URI"
|
||||||
|
|
|
@ -47,7 +47,7 @@ class HelpersTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'redirect' do
|
describe 'redirect' do
|
||||||
it 'uses a 302 when only a path is given' do
|
it 'uses a 303 when only a path is given' do
|
||||||
mock_app {
|
mock_app {
|
||||||
get '/' do
|
get '/' do
|
||||||
redirect '/foo'
|
redirect '/foo'
|
||||||
|
@ -56,7 +56,7 @@ class HelpersTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
get '/'
|
get '/'
|
||||||
assert_equal 302, status
|
assert_equal 303, status
|
||||||
assert_equal '', body
|
assert_equal '', body
|
||||||
assert_equal 'http://example.org/foo', response['Location']
|
assert_equal 'http://example.org/foo', response['Location']
|
||||||
end
|
end
|
||||||
|
@ -84,7 +84,7 @@ class HelpersTest < Test::Unit::TestCase
|
||||||
|
|
||||||
request = Rack::MockRequest.new(@app)
|
request = Rack::MockRequest.new(@app)
|
||||||
response = request.get('/try_redirect', 'HTTP_REFERER' => '/foo')
|
response = request.get('/try_redirect', 'HTTP_REFERER' => '/foo')
|
||||||
assert_equal 302, response.status
|
assert_equal 303, response.status
|
||||||
assert_equal 'http://example.org/foo', response['Location']
|
assert_equal 'http://example.org/foo', response['Location']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue