mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
use status code 303 for redirects
This commit is contained in:
parent
b3942697a6
commit
c0eb84faa6
3 changed files with 8 additions and 4 deletions
2
CHANGES
2
CHANGES
|
@ -42,6 +42,8 @@
|
|||
|
||||
* Improved error handling. (cactus, Konstantin Haase)
|
||||
|
||||
* Use 303 instead of 302 for redirects. (Konstantin Haase)
|
||||
|
||||
* Skip missing template engines in tests correctly. (cactus)
|
||||
|
||||
* 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.
|
||||
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
|
||||
# single absolute URI"
|
||||
|
|
|
@ -47,7 +47,7 @@ class HelpersTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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 {
|
||||
get '/' do
|
||||
redirect '/foo'
|
||||
|
@ -56,7 +56,7 @@ class HelpersTest < Test::Unit::TestCase
|
|||
}
|
||||
|
||||
get '/'
|
||||
assert_equal 302, status
|
||||
assert_equal 303, status
|
||||
assert_equal '', body
|
||||
assert_equal 'http://example.org/foo', response['Location']
|
||||
end
|
||||
|
@ -84,7 +84,7 @@ class HelpersTest < Test::Unit::TestCase
|
|||
|
||||
request = Rack::MockRequest.new(@app)
|
||||
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']
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue