Permalink
Browse files

only manually call Response#finish for parallel requests

  • Loading branch information...
1 parent deb794f commit fa8c3f1674254c24fc93bbe2e23e77eaa9f8366a @technoweenie technoweenie committed Feb 19, 2011
View
1 lib/faraday/adapter/patron.rb
@@ -22,7 +22,6 @@ def call(env)
: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
View
2 lib/faraday/adapter/test.rb
@@ -7,7 +7,7 @@ class Adapter
# end
# end
# end
- #
+ #
# resp = test.get '/nigiri/sake.json'
# resp.body # => 'hi world'
#
View
5 lib/faraday/adapter/typhoeus.rb
@@ -26,18 +26,19 @@ def call(env)
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
View
2 lib/faraday/error.rb
@@ -6,7 +6,7 @@ def initialize(exception)
end
def message
- @inner_exception.respond_to?(:message) ?
+ @inner_exception.respond_to?(:message) ?
@inner_exception.message :
@inner_exception.to_s
end
View
5 lib/faraday/request.rb
@@ -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
#
View
1 lib/faraday/response.rb
@@ -41,6 +41,7 @@ def on_complete(&block)
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]

0 comments on commit fa8c3f1

Please sign in to comment.