aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-12-10 05:53:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-12-10 05:53:56 +0000
commitc81fff2468bbf597457bf57cd599d2d4be77c715 (patch)
tree0c0b7949633554dee61aed775a79c06ba309d51f /activeresource
parent83b0204138a178d0e24e3d9aec454dd283a5185e (diff)
downloadrails-c81fff2468bbf597457bf57cd599d2d4be77c715.tar.gz
rails-c81fff2468bbf597457bf57cd599d2d4be77c715.tar.bz2
rails-c81fff2468bbf597457bf57cd599d2d4be77c715.zip
Correct empty response handling. Closes #10445.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/CHANGELOG5
-rw-r--r--activeresource/lib/active_resource/base.rb2
-rw-r--r--activeresource/lib/active_resource/connection.rb2
-rw-r--r--activeresource/lib/active_resource/http_mock.rb15
4 files changed, 20 insertions, 4 deletions
diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG
index 02769db088..b02b6161e3 100644
--- a/activeresource/CHANGELOG
+++ b/activeresource/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Correct empty response handling. #10445 [seangeo]
+
+
*2.0.1* (December 7th, 2007)
* Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 [kou]
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index cc929aaee0..47c4d0c8f1 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -807,7 +807,7 @@ module ActiveResource
end
def load_attributes_from_response(response)
- if response['Content-size'] != "0" && response.body.strip.size > 0
+ if response['Content-Length'] != "0" && response.body.strip.size > 0
load(self.class.format.decode(response.body))
end
end
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 46d462dbe7..fba393ff89 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -99,7 +99,7 @@ module ActiveResource
logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
result = nil
time = Benchmark.realtime { result = http.send(method, path, *arguments) }
- logger.info "--> #{result.code} #{result.message} (#{result.body.length}b %.2fs)" % time if logger
+ logger.info "--> #{result.code} #{result.message} (#{result.body ? result.body : 0}b %.2fs)" % time if logger
handle_response(result)
end
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 37fc1f2bfe..b54bf09c2d 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -34,7 +34,7 @@ module ActiveResource
end
if block_given?
- yield Responder.new(responses)
+ yield Responder.new(responses)
else
Responder.new(responses)
end
@@ -102,6 +102,17 @@ module ActiveResource
def initialize(body, message = 200, headers = {})
@body, @message, @headers = body, message.to_s, headers
@code = @message[0,3].to_i
+
+ resp_cls = Net::HTTPResponse::CODE_TO_OBJ[@code.to_s]
+ if resp_cls && !resp_cls.body_permitted?
+ @body = nil
+ end
+
+ if @body.nil?
+ self['Content-Length'] = "0"
+ else
+ self['Content-Length'] = body.size.to_s
+ end
end
def success?
@@ -115,7 +126,7 @@ module ActiveResource
def []=(key, value)
headers[key] = value
end
-
+
def ==(other)
if (other.is_a?(Response))
other.body == body && other.message == message && other.headers == headers