aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
authorJohn Mileham <jmileham@gmail.com>2011-08-23 19:04:35 -0400
committerJohn Mileham <jmileham@gmail.com>2011-09-11 14:46:50 -0400
commita06d17480ff533fbc375df219a4e70886fb4899b (patch)
tree55a5054486b2a5bb76fd17ea6c17d9205ce0b15f /activeresource/lib
parentf776661fd2d93f9a8c01f97a4c4bc3ca97c3718d (diff)
downloadrails-a06d17480ff533fbc375df219a4e70886fb4899b.tar.gz
rails-a06d17480ff533fbc375df219a4e70886fb4899b.tar.bz2
rails-a06d17480ff533fbc375df219a4e70886fb4899b.zip
ActiveResource shouldn't rely on the presence of Content-Length
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/base.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 693bd0592e..236dc565f3 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -1357,7 +1357,9 @@ module ActiveResource
end
def load_attributes_from_response(response)
- if !response['Content-Length'].blank? && response['Content-Length'] != "0" && !response.body.nil? && response.body.strip.size > 0
+ if (response_code_allows_body?(response.code) &&
+ (response['Content-Length'].nil? || response['Content-Length'] != "0") &&
+ !response.body.nil? && response.body.strip.size > 0)
load(self.class.format.decode(response.body), true)
@persisted = true
end
@@ -1381,6 +1383,12 @@ module ActiveResource
end
private
+
+ # Determine whether the response is allowed to have a body per HTTP 1.1 spec section 4.4.1
+ def response_code_allows_body?(c)
+ !((100..199).include?(c) || [204,304].include?(c))
+ end
+
# Tries to find a resource for a given collection name; if it fails, then the resource is created
def find_or_create_resource_for_collection(name)
find_or_create_resource_for(ActiveSupport::Inflector.singularize(name.to_s))