Class: Faraday::Adapter

Inherits:
Middleware show all
Extended by:
Parallelism, AutoloadHelper, MiddlewareRegistry
Defined in:
lib/faraday/adapter.rb,
lib/faraday/adapter/rack.rb,
lib/faraday/adapter/test.rb,
lib/faraday/adapter/excon.rb,
lib/faraday/adapter/patron.rb,
lib/faraday/adapter/em_http.rb,
lib/faraday/adapter/net_http.rb,
lib/faraday/adapter/typhoeus.rb,
lib/faraday/adapter/httpclient.rb,
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/adapter/net_http_persistent.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

Public: This is a base class for all Faraday adapters. Adapters are responsible for fulfilling a Faraday request.

Direct Known Subclasses

EMHttp, EMSynchrony, Excon, HTTPClient, NetHttp, Patron, Rack, Test, Typhoeus

Defined Under Namespace

Modules: Parallelism Classes: EMHttp, EMSynchrony, Excon, HTTPClient, NetHttp, NetHttpPersistent, Patron, Rack, Test, Typhoeus

Constant Summary collapse

CONTENT_LENGTH =
'Content-Length'.freeze

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AutoloadHelper

all_loaded_constants, autoload_all, load_autoloaded_constants

Methods included from MiddlewareRegistry

lookup_middleware, register_middleware

Methods included from Parallelism

inherited, supports_parallel?

Methods inherited from Middleware

dependency, inherited, #initialize, loaded?, new

Constructor Details

This class inherits a constructor from Faraday::Middleware

Class Method Details

.adapter?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/faraday/adapter.rb', line 48

def self.adapter?
  true
end

Instance Method Details

#call(env) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/faraday/adapter.rb', line 52

def call(env)
  if !env[:body] and Connection::METHODS_WITH_BODIES.include? env[:method]
    # play nice and indicate we're sending an empty body
    env[:request_headers][CONTENT_LENGTH] = "0"
    # Typhoeus hangs on PUT requests if body is nil
    env[:body] = ''
  end
end

#prepend_proxy_auth_string(proxy, session) ⇒ Object



61
62
63
# File 'lib/faraday/adapter/patron.rb', line 61

def prepend_proxy_auth_string(proxy, session)
  session.proxy.insert(7, "#{proxy[:user]}:#{proxy[:password]}@")
end

#save_response(env, status, body, headers = nil) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/faraday/adapter.rb', line 61

def save_response(env, status, body, headers = nil)
  env[:status] = status
  env[:body] = body
  env[:response_headers] = Utils::Headers.new.tap do |response_headers|
    response_headers.update headers unless headers.nil?
    yield response_headers if block_given?
  end
end