Skip to content

Commit

Permalink
activeresource should treat HTTP status 307 as redirection, same as 3…
Browse files Browse the repository at this point in the history
…01 and 302; added missing test cases for statii 301 and 302.
  • Loading branch information
jimherz committed Oct 12, 2011
1 parent fa79408 commit a78a75d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions activeresource/lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activeresource/lib/active_resource/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
when 301,302,307
raise(Redirection.new(response))
when 200...400
response
Expand Down
9 changes: 9 additions & 0 deletions activeresource/test/cases/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def test_handle_response
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

Expand Down

0 comments on commit a78a75d

Please sign in to comment.