Async::HTTP::FaradaySourceAsyncHTTPFaradayAdapter

class Adapter

An adapter that allows Faraday to use Async::HTTP as the underlying HTTP client.

Definitions

CONNECTION_EXCEPTIONS

The exceptions that are considered connection errors and result in a Faraday::ConnectionFailed exception.

Implementation

CONNECTION_EXCEPTIONS = [
	Errno::EADDRNOTAVAIL,
	Errno::ECONNABORTED,
	Errno::ECONNREFUSED,
	Errno::ECONNRESET,
	Errno::EHOSTUNREACH,
	Errno::EINVAL,
	Errno::ENETUNREACH,
	Errno::EPIPE,
	IOError,
	SocketError
].freeze

def initialize(...)

Create a Farady compatible adapter.

Signature

parameter timeout Integer

The timeout for requests.

parameter options Hash

Additional options to pass to the underlying Async::HTTP::Client.

Implementation

def initialize(...)
	super
	
	@timeout = @connection_options.delete(:timeout)
	
	if clients = @connection_options.delete(:clients)
		@clients = clients.call(**@connection_options, &@config_block)
	else
		@clients = PerThreadPersistentClients.new(**@connection_options, &@config_block)
	end
end

def close

Close all clients.

Implementation

def close
	# The order of operations here is to avoid a race condition between iterating over clients (#close may yield) and creating new clients.
	@clients.close
end

def call(env)

Make a request using the adapter.

Signature

parameter env Faraday::Env

The environment to make the request in.

raises Faraday::TimeoutError

If the request times out.

raises Faraday::SSLError

If there is an SSL error.

raises Faraday::ConnectionFailed

If there is a connection error.

Implementation

def call(env)
	super
	
	# For compatibility with the default adapter:
	env.url.path = '/' if env.url.path.empty?
	
	if parallel_manager = env.parallel_manager
		parallel_manager.async do
			perform_request(env)
			env.response.finish(env)
		end
	else
		perform_request(env)
	end
	
	@app.call(env)
end