diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2011-10-11 20:43:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2011-10-11 20:54:06 -0700 |
commit | 027ecd3afbabb678b5cd161a494641c21c90531d (patch) | |
tree | a1500200adbf85a4fc291a9261ec35a2c997ce9a | |
parent | fa79408a559d250c59ab4dac34dc7e68e6b7533f (diff) | |
parent | a78a75d67a8072bc7613edbed548d4b865daadf8 (diff) | |
download | rails-027ecd3afbabb678b5cd161a494641c21c90531d.tar.gz rails-027ecd3afbabb678b5cd161a494641c21c90531d.tar.bz2 rails-027ecd3afbabb678b5cd161a494641c21c90531d.zip |
Merge remote-tracking branch 'jimherz/activeresource_redirection_patch'
Closes #3302
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 4 | ||||
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 2 | ||||
-rw-r--r-- | activeresource/test/cases/connection_test.rb | 9 |
3 files changed, 12 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 03c4cc5b9e..3fb8ce7790 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/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) - # * 301, 302 - ActiveResource::Redirection + # * 200..399 - Valid response, no exception (other than 301, 302 and 307) + # * 301, 302, 307 - ActiveResource::Redirection # * 400 - ActiveResource::BadRequest # * 401 - ActiveResource::UnauthorizedAccess # * 403 - ActiveResource::ForbiddenAccess diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 592fca96a4..73410c2d82 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -122,7 +122,7 @@ module ActiveResource # Handles response and error codes from the remote service. def handle_response(response) case response.code.to_i - when 301,302 + when 301,302,307 raise(Redirection.new(response)) when 200...400 response diff --git a/activeresource/test/cases/connection_test.rb b/activeresource/test/cases/connection_test.rb index 09df0fb678..6f33023832 100644 --- a/activeresource/test/cases/connection_test.rb +++ b/activeresource/test/cases/connection_test.rb @@ -38,6 +38,15 @@ class ConnectionTest < Test::Unit::TestCase assert_equal expected, handle_response(expected) end + # 301 is moved permanently (redirect) + assert_response_raises ActiveResource::Redirection, 301 + + # 302 is found (redirect) + assert_response_raises ActiveResource::Redirection, 302 + + # 307 is temporary redirect + assert_response_raises ActiveResource::Redirection, 307 + # 400 is a bad request (e.g. malformed URI or missing request parameter) assert_response_raises ActiveResource::BadRequest, 400 |