lib/async/http/client.rb in async-http-0.80.1 vs lib/async/http/client.rb in async-http-0.81.0

- old
+ new

@@ -16,11 +16,10 @@ 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. @@ -28,16 +27,16 @@ # 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: DEFAULT_RETRIES, connection_limit: DEFAULT_CONNECTION_LIMIT) + def initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, retries: DEFAULT_RETRIES, **options) @endpoint = endpoint @protocol = protocol @retries = retries - @pool = make_pool(connection_limit) + @pool = make_pool(**options) @scheme = scheme @authority = authority end @@ -189,11 +188,23 @@ response.pool = @pool return response end - def make_pool(connection_limit) - Async::Pool::Controller.wrap(limit: connection_limit) do + def assign_default_tags(tags) + tags[:endpoint] = @endpoint.to_s + tags[:protocol] = @protocol.to_s + end + + def make_pool(**options) + if connection_limit = options.delete(:connection_limit) + warn "The connection_limit: option is deprecated, please use limit: instead.", uplevel: 2 + options[:limit] = connection_limit + end + + self.assign_default_tags(options[:tags] ||= {}) + + Async::Pool::Controller.wrap(**options) do Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"} @protocol.client(@endpoint.connect) end end