Skip to content
Browse files

Correct empty response handling. Closes #10445.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 83b0204 commit c81fff2468bbf597457bf57cd599d2d4be77c715 @jeremy jeremy committed Dec 10, 2007
View
5 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]
View
2 activeresource/lib/active_resource/base.rb
@@ -807,7 +807,7 @@ def create
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
View
2 activeresource/lib/active_resource/connection.rb
@@ -99,7 +99,7 @@ def request(method, path, *arguments)
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
View
15 activeresource/lib/active_resource/http_mock.rb
@@ -34,7 +34,7 @@ def respond_to(pairs = {})
end
if block_given?
- yield Responder.new(responses)
+ yield Responder.new(responses)
else
Responder.new(responses)
end
@@ -102,6 +102,17 @@ class Response
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 @@ def [](key)
def []=(key, value)
headers[key] = value
end
-
+
def ==(other)
if (other.is_a?(Response))
other.body == body && other.message == message && other.headers == headers

0 comments on commit c81fff2

Please sign in to comment.
Something went wrong with that request. Please try again.