Async::HTTP::FaradaySourceAsyncHTTPFaradayPersistentClients

class PersistentClients

An interface for creating and managing persistent HTTP clients.

Definitions

def initialize(...)

Create a new instance of the class.

Implementation

def initialize(...)
	super
	
	@clients = {}
end

def close

Close all clients.

Implementation

def close
	super
	
	clients = @clients.values
	@clients.clear
	
	clients.each(&:close)
end

def make_client(endpoint)

Lookup or create a client for the given endpoint.

Signature

parameter endpoint IO::Endpoint::Generic

The endpoint to create the client for.

Implementation

def make_client(endpoint)
	key = host_key(endpoint)
	
	fetch(key) do
		super
	end
end

def with_client(endpoint)

Get a client for the given endpoint. If a client already exists for the host, it will be reused.

Signature

yields {|client| ...}

A client for the given endpoint.

Implementation

def with_client(endpoint)
	yield make_client(endpoint)
end

def with_proxied_client(proxy_endpoint, endpoint)

Get a client for the given proxy endpoint and endpoint. If a client already exists for the host, it will be reused.

Signature

parameter proxy_endpoint IO::Endpoint::Generic

The proxy endpoint to use.

parameter endpoint IO::Endpoint::Generic

The endpoint to get the client for.

Implementation

def with_proxied_client(proxy_endpoint, endpoint)
	key = [host_key(proxy_endpoint), host_key(endpoint)]
	
	proxied_client = fetch(key) do
		make_client(proxy_endpoint).proxied_client(endpoint)
	end
	
	yield proxied_client
end