Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Treat 303 See Other as a redirect response, too

  • Loading branch information...
commit b8bb5f44c8ba02786ed42d04f66641f236ef42c3 1 parent 027ecd3
@jeremy jeremy authored
View
13 activeresource/CHANGELOG
@@ -1,3 +1,16 @@
+*Rails 3.1.2 (unreleased)*
+
+* Redirect responses: 303 See Other and 307 Temporary Redirect now behave like
+ 301 Moved Permanently and 302 Found. GH #3302.
+
+ [Jim Herz]
+
+
+*Rails 3.1.1 (October 7, 2011)*
+
+* No changes.
+
+
*Rails 3.1.0 (August 30, 2011)*
* The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set `self.format = :xml` in the class. eg.
View
4 activeresource/lib/active_resource/base.rb
@@ -170,8 +170,8 @@ module ActiveResource
# <tt>404</tt> is just one of the HTTP error response codes that Active Resource will handle with its own exception. The
# following HTTP response codes will also result in these exceptions:
#
- # * 200..399 - Valid response, no exception (other than 301, 302 and 307)
- # * 301, 302, 307 - ActiveResource::Redirection
+ # * 200..399 - Valid response. No exceptions, other than these redirects:
+ # * 301, 302, 303, 307 - ActiveResource::Redirection
# * 400 - ActiveResource::BadRequest
# * 401 - ActiveResource::UnauthorizedAccess
# * 403 - ActiveResource::ForbiddenAccess
View
2  activeresource/lib/active_resource/connection.rb
@@ -122,7 +122,7 @@ def request(method, path, *arguments)
# Handles response and error codes from the remote service.
def handle_response(response)
case response.code.to_i
- when 301,302,307
+ when 301, 302, 303, 307
raise(Redirection.new(response))
when 200...400
response
View
16 activeresource/test/cases/connection_test.rb
@@ -2,6 +2,7 @@
class ConnectionTest < Test::Unit::TestCase
ResponseCodeStub = Struct.new(:code)
+ RedirectResponseStub = Struct.new(:code, :Location)
def setup
@conn = ActiveResource::Connection.new('http://localhost')
@@ -39,13 +40,16 @@ def test_handle_response
end
# 301 is moved permanently (redirect)
- assert_response_raises ActiveResource::Redirection, 301
+ assert_redirect_raises 301
# 302 is found (redirect)
- assert_response_raises ActiveResource::Redirection, 302
+ assert_redirect_raises 302
+
+ # 303 is see other (redirect)
+ assert_redirect_raises 303
# 307 is temporary redirect
- assert_response_raises ActiveResource::Redirection, 307
+ assert_redirect_raises 307
# 400 is a bad request (e.g. malformed URI or missing request parameter)
assert_response_raises ActiveResource::BadRequest, 400
@@ -256,6 +260,12 @@ def assert_response_raises(klass, code)
end
end
+ def assert_redirect_raises(code)
+ assert_raise(ActiveResource::Redirection, "Expected response code #{code} to raise ActiveResource::Redirection") do
+ handle_response RedirectResponseStub.new(code, 'http://example.com/')
+ end
+ end
+
def handle_response(response)
@conn.__send__(:handle_response, response)
end
Please sign in to comment.
Something went wrong with that request. Please try again.