Class: Faraday::Adapter::Excon

### Home Classes Methods

### In Files

- lib/faraday/adapter/excon.rb

### Parent

Faraday::Adapter

### Methods

- ::new
- #call
- #read_body

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::Adapter::Excon

### Public Class Methods

new(app, connection_options = {}) click to toggle source

    # File lib/faraday/adapter/excon.rb, line 6
    def initialize(app, connection_options = {})
      @connection_options = connection_options
      super(app)
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/faraday/adapter/excon.rb, line 11
    def call(env)
      super

      opts = {}
      if env[:url].scheme == 'https' && ssl = env[:ssl]
        opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
        opts[:ssl_ca_path] = ssl[:ca_path] if ssl[:ca_path]
        opts[:ssl_ca_file] = ssl[:ca_file] if ssl[:ca_file]
        opts[:client_cert] = ssl[:client_cert] if ssl[:client_cert]
        opts[:client_key]  = ssl[:client_key]  if ssl[:client_key]
        opts[:certificate] = ssl[:certificate] if ssl[:certificate]
        opts[:private_key] = ssl[:private_key] if ssl[:private_key]

        # https://github.com/geemus/excon/issues/106
        # https://github.com/jruby/jruby-ossl/issues/19
        opts[:nonblock] = false
      end

      if ( req = env[:request] )
        if req[:timeout]
          opts[:read_timeout]      = req[:timeout]
          opts[:connect_timeout]   = req[:timeout]
          opts[:write_timeout]     = req[:timeout]
        end

        if req[:open_timeout]
          opts[:connect_timeout]   = req[:open_timeout]
          opts[:write_timeout]     = req[:open_timeout]
        end

        if req[:proxy]
          opts[:proxy] = {
            :host     => req[:proxy][:uri].host,
            :port     => req[:proxy][:uri].port,
            :scheme   => req[:proxy][:uri].scheme,
            :user     => req[:proxy][:user],
            :password => req[:proxy][:password]
          }
        end
      end

      conn = ::Excon.new(env[:url].to_s, opts.merge(@connection_options))

      resp = conn.request            :method  => env[:method].to_s.upcase,
        :headers => env[:request_headers],
        :body    => read_body(env)

      save_response(env, resp.status.to_i, resp.body, resp.headers)

      @app.call env
    rescue ::Excon::Errors::SocketError => err
      if err.message =~ /\btimeout\b/
        raise Error::TimeoutError, err
      elsif err.message =~ /\bcertificate\b/
        raise Faraday::SSLError, err
      else
        raise Error::ConnectionFailed, err
      end
    rescue ::Excon::Errors::Timeout => err
      raise Error::TimeoutError, err
    end

read_body(env) click to toggle source

TODO: support streaming requests

    # File lib/faraday/adapter/excon.rb, line 75
    def read_body(env)
      env[:body].respond_to?(:read) ? env[:body].read : env[:body]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.