1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Correct empty response handling. Closes #10445.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-12-10 05:53:56 +00:00
parent 83b0204138
commit c81fff2468
4 changed files with 20 additions and 4 deletions

View file

@ -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 file

@ -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

View file

@ -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

View file

@ -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