Class: Faraday::Adapter::HTTPX

Inherits:
Faraday::Adapter show all
Includes:
RequestMixin
Defined in:
lib/httpx/adapters/faraday.rb

Defined Under Namespace

Modules: OnDataPlugin, ReasonPlugin, RequestMixin Classes: ParallelManager

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RequestMixin

#build_connection, #close

Class Method Details

.setup_parallel_manager(options = {}) ⇒ Object



245
246
247
# File 'lib/httpx/adapters/faraday.rb', line 245

def setup_parallel_manager(options = {})
  ParallelManager.new(options)
end

Instance Method Details

#call(env) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/httpx/adapters/faraday.rb', line 250

def call(env)
  super
  if parallel?(env)
    handler = env[:parallel_manager].enqueue(env)
    handler.on_response do |response|
      if response.is_a?(::HTTPX::Response)
        save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers|
          response_headers.merge!(response.headers)
        end
      else
        env[:error] = response.error
        save_response(env, 0, "", {}, nil)
      end
    end
    return handler
  end

  response = connect_and_request(env)
  save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers|
    response_headers.merge!(response.headers)
  end
  @app.call(env)
end