only manually call Response#finish for parallel requests

This commit is contained in:
rick 2011-02-19 12:27:20 -08:00
parent deb794faad
commit fa8c3f1674
6 changed files with 9 additions and 7 deletions

View File

@ -22,7 +22,6 @@ module Faraday
:response_headers => resp.headers. :response_headers => resp.headers.
inject({}) { |memo, (k, v)| memo.update(k.downcase => v) }, inject({}) { |memo, (k, v)| memo.update(k.downcase => v) },
:body => resp.body :body => resp.body
env[:response].finish(env)
@app.call env @app.call env
rescue Errno::ECONNREFUSED rescue Errno::ECONNREFUSED

View File

@ -7,7 +7,7 @@ module Faraday
# end # end
# end # end
# end # end
# #
# resp = test.get '/nigiri/sake.json' # resp = test.get '/nigiri/sake.json'
# resp.body # => 'hi world' # resp.body # => 'hi world'
# #

View File

@ -26,18 +26,19 @@ module Faraday
req.timeout = req.connect_timeout = (env_req[:timeout] * 1000) if env_req[:timeout] req.timeout = req.connect_timeout = (env_req[:timeout] * 1000) if env_req[:timeout]
req.connect_timeout = (env_req[:open_timeout] * 1000) if env_req[:open_timeout] req.connect_timeout = (env_req[:open_timeout] * 1000) if env_req[:open_timeout]
is_parallel = !!env[:parallel_manager]
req.on_complete do |resp| req.on_complete do |resp|
env.update \ env.update \
:status => resp.code, :status => resp.code,
:response_headers => parse_response_headers(resp.headers), :response_headers => parse_response_headers(resp.headers),
:body => resp.body :body => resp.body
env[:response].finish(env) env[:response].finish(env) if !is_parallel
end end
hydra = env[:parallel_manager] || self.class.setup_parallel_manager hydra = env[:parallel_manager] || self.class.setup_parallel_manager
hydra.queue req hydra.queue req
if !env[:parallel_manager] if !is_parallel
hydra.run hydra.run
end end

View File

@ -6,7 +6,7 @@ module Faraday
end end
def message def message
@inner_exception.respond_to?(:message) ? @inner_exception.respond_to?(:message) ?
@inner_exception.message : @inner_exception.message :
@inner_exception.to_s @inner_exception.to_s
end end

View File

@ -3,8 +3,9 @@ module Faraday
# #
# @connection.post do |req| # @connection.post do |req|
# req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1' # req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
# req.headers['b'] = '2' # header # req.headers['b'] = '2' # Header
# req['b'] = '2' # header # req.params['c'] = '3' # GET Param
# req['b'] = '2' # also Header
# req.body = 'abc' # req.body = 'abc'
# end # end
# #

View File

@ -41,6 +41,7 @@ module Faraday
end end
def finish(env) def finish(env)
return self if @status
env[:body] ||= '' env[:body] ||= ''
@on_complete_callbacks.each { |c| c.call(env) } @on_complete_callbacks.each { |c| c.call(env) }
@status, @headers, @body = env[:status], env[:response_headers], env[:body] @status, @headers, @body = env[:status], env[:response_headers], env[:body]