lib/async/http/client.rb in async-http-0.35.1 vs lib/async/http/client.rb in async-http-0.36.0
- old
+ new
@@ -26,27 +26,30 @@
require_relative 'middleware'
module Async
module HTTP
class Client
- def initialize(endpoint, protocol = endpoint.protocol, authority = endpoint.hostname, retries: 3, **options)
+ def initialize(endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme, authority = endpoint.authority, retries: 3, connection_limit: nil)
@endpoint = endpoint
-
@protocol = protocol
- @authority = authority
@retries = retries
- @pool = connect(**options)
+ @pool = make_pool(connection_limit)
+
+ @scheme = scheme
+ @authority = authority
end
attr :endpoint
attr :protocol
- attr :authority
attr :retries
attr :pool
+ attr :scheme
+ attr :authority
+
def self.open(*args, &block)
client = self.new(*args)
return client unless block_given?
@@ -62,11 +65,13 @@
end
include Methods
def call(request)
- request.authority ||= @authority
+ request.scheme ||= self.scheme
+ request.authority ||= self.authority
+
attempt = 0
# We may retry the request if it is possible to do so. https://tools.ietf.org/html/draft-nottingham-httpbis-retry-01 is a good guide for how retrying requests should work.
begin
attempt += 1
@@ -103,10 +108,10 @@
end
end
protected
- def connect(connection_limit: nil)
+ def make_pool(connection_limit = nil)
Pool.new(connection_limit) do
Async.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}
peer = @endpoint.connect
peer.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)