lib/async/http/client.rb in async-http-0.49.1 vs lib/async/http/client.rb in async-http-0.50.0

- old
+ new

@@ -21,28 +21,33 @@ # THE SOFTWARE. require 'async/io/endpoint' require 'async/io/stream' +require 'async/pool/controller' + require 'protocol/http/body/streamable' require 'protocol/http/methods' require_relative 'protocol' module Async module HTTP + DEFAULT_RETRIES = 3 + DEFAULT_CONNECTION_LIMIT = nil + class Client < ::Protocol::HTTP::Methods # Provides a robust interface to a server. # * If there are no connections, it will create one. # * If there are already connections, it will reuse it. # * If a request fails, it will retry it up to N times if it was idempotent. # The client object will never become unusable. It internally manages persistent connections (or non-persistent connections if that's required). # @param endpoint [Endpoint] the endpoint to connnect to. # @param protocol [Protocol::HTTP1 | Protocol::HTTP2 | Protocol::HTTPS] the protocol to use. # @param scheme [String] The default scheme to set to requests. # @param authority [String] The default authority to set to requests. - def initialize(endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme, authority = endpoint.authority, retries: 3, connection_limit: nil) + def initialize(endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme, authority = endpoint.authority, retries: DEFAULT_RETRIES, connection_limit: DEFAULT_CONNECTION_LIMIT) @endpoint = endpoint @protocol = protocol @retries = retries @pool = make_pool(connection_limit) @@ -127,10 +132,10 @@ end protected def make_pool(connection_limit) - Pool.new(connection_limit) do + Async::Pool::Controller.wrap(limit: connection_limit) do Async.logger.debug(self) {"Making connection to #{@endpoint.inspect}"} @protocol.client(@endpoint.connect) end end