Class: Faraday::Adapter::Patron

### Home Classes Methods

### In Files

- lib/faraday/adapter/patron.rb

### Parent

Faraday::Adapter

### Methods

- ::new
- #call
- #create_session

### 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::Patron

### Public Class Methods

new(app, &block) click to toggle source

    # File lib/faraday/adapter/patron.rb, line 6
    def initialize(app, &block)
      super(app)
      @block = block
    end

### Public Instance Methods

call(env) click to toggle source

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

      # TODO: support streaming requests
      env[:body] = env[:body].read if env[:body].respond_to? :read

      session = @session ||= create_session

      if req = env[:request]
        session.timeout = session.connect_timeout = req[:timeout] if req[:timeout]
        session.connect_timeout = req[:open_timeout]              if req[:open_timeout]

        if proxy = req[:proxy]
          proxy_uri = proxy[:uri].dup
          proxy_uri.user = proxy[:user] && Utils.escape(proxy[:user]).gsub('+', '%20')
          proxy_uri.password = proxy[:password] && Utils.escape(proxy[:password]).gsub('+', '%20')
          session.proxy = proxy_uri.to_s
        end
      end

      response = begin
        data = env[:body] ? env[:body].to_s : nil
        session.request(env[:method], env[:url].to_s, env[:request_headers], :data => data)
      rescue Errno::ECONNREFUSED, ::Patron::ConnectionFailed
        raise Error::ConnectionFailed, $!
      end

      save_response(env, response.status, response.body, response.headers)

      @app.call env
    rescue ::Patron::TimeoutError => err
      if err.message == "Connection time-out"
        raise Faraday::Error::ConnectionFailed, err
      else
        raise Faraday::Error::TimeoutError, err
      end
    rescue ::Patron::Error => err
      if err.message.include?("code 407")
        raise Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
      else
        raise Error::ConnectionFailed, err
      end
    end

create_session() click to toggle source

    # File lib/faraday/adapter/patron.rb, line 64
    def create_session
      session = ::Patron::Session.new
      session.insecure = true
      @block.call(session) if @block
      session
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.