Class: Gel::Httpool
Constant Summary collapse
- Logger =
::Logger.new($stderr)
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Httpool
constructor
A new instance of Httpool.
- #request(uri, request = Net::HTTP::Get.new(uri)) ⇒ Object
Constructor Details
#initialize ⇒ Httpool
Returns a new instance of Httpool.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gel/httpool.rb', line 13 def initialize super() @pool = {} @cond = new_cond if block_given? begin yield self ensure close end end end |
Instance Method Details
#close ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gel/httpool.rb', line 43 def close https = nil synchronize do https = @pool.values.flatten @pool = nil @cond.broadcast end https.each(&:finish) end |
#request(uri, request = Net::HTTP::Get.new(uri)) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gel/httpool.rb', line 28 def request(uri, request = Net::HTTP::Get.new(uri)) with_connection(uri) do |http| logger.debug { "GET #{uri}" } if uri.user request.basic_auth(uri.user, uri.password || "") end t = Time.now response = http.request(request) logger.debug { "HTTP #{response.code} (#{response.}) #{uri} [#{Time.now - t}s]" } response end end |