diff --git a/CHANGES b/CHANGES index ae49d461..83d94f72 100644 --- a/CHANGES +++ b/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 diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index f1ff20e5..a02397bd 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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" diff --git a/test/helpers_test.rb b/test/helpers_test.rb index bee2d005..89581a96 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -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