Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use 303 for redirects from post for HTTP/1.1 (fixes ajax redirects in…

… Internet Explorer 9)
  • Loading branch information...
commit 5a16e33f91f8581ac54f0853acf5334ac362cb1c 1 parent f1b3507
@rkh rkh authored
Showing with 21 additions and 1 deletion.
  1. +5 −1 lib/sinatra/base.rb
  2. +16 −0 test/helpers_test.rb
View
6 lib/sinatra/base.rb
@@ -113,7 +113,11 @@ def block.each; yield(call) end
# 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"
View
16 test/helpers_test.rb
@@ -207,6 +207,22 @@ def status_app(code, &block)
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
Please sign in to comment.
Something went wrong with that request. Please try again.