mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
only manually call Response#finish for parallel requests
This commit is contained in:
parent
deb794faad
commit
fa8c3f1674
@ -22,7 +22,6 @@ module Faraday
|
||||
:response_headers => resp.headers.
|
||||
inject({}) { |memo, (k, v)| memo.update(k.downcase => v) },
|
||||
:body => resp.body
|
||||
env[:response].finish(env)
|
||||
|
||||
@app.call env
|
||||
rescue Errno::ECONNREFUSED
|
||||
|
@ -7,7 +7,7 @@ module Faraday
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
# resp = test.get '/nigiri/sake.json'
|
||||
# resp.body # => 'hi world'
|
||||
#
|
||||
|
@ -26,18 +26,19 @@ module Faraday
|
||||
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]
|
||||
|
||||
is_parallel = !!env[:parallel_manager]
|
||||
req.on_complete do |resp|
|
||||
env.update \
|
||||
:status => resp.code,
|
||||
:response_headers => parse_response_headers(resp.headers),
|
||||
:body => resp.body
|
||||
env[:response].finish(env)
|
||||
env[:response].finish(env) if !is_parallel
|
||||
end
|
||||
|
||||
hydra = env[:parallel_manager] || self.class.setup_parallel_manager
|
||||
hydra.queue req
|
||||
|
||||
if !env[:parallel_manager]
|
||||
if !is_parallel
|
||||
hydra.run
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def message
|
||||
@inner_exception.respond_to?(:message) ?
|
||||
@inner_exception.respond_to?(:message) ?
|
||||
@inner_exception.message :
|
||||
@inner_exception.to_s
|
||||
end
|
||||
|
@ -3,8 +3,9 @@ module Faraday
|
||||
#
|
||||
# @connection.post do |req|
|
||||
# req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
|
||||
# req.headers['b'] = '2' # header
|
||||
# req['b'] = '2' # header
|
||||
# req.headers['b'] = '2' # Header
|
||||
# req.params['c'] = '3' # GET Param
|
||||
# req['b'] = '2' # also Header
|
||||
# req.body = 'abc'
|
||||
# end
|
||||
#
|
||||
|
@ -41,6 +41,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def finish(env)
|
||||
return self if @status
|
||||
env[:body] ||= ''
|
||||
@on_complete_callbacks.each { |c| c.call(env) }
|
||||
@status, @headers, @body = env[:status], env[:response_headers], env[:body]
|
||||
|
Loading…
x
Reference in New Issue
Block a user