Class: Faraday::Adapter::Rack

### Home Classes Methods

### In Files

- lib/faraday/adapter/rack.rb

### Parent

Faraday::Adapter

### Methods

- ::new
- #call
- #execute_request

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

Sends requests to a Rack app.

Examples

    class MyRackApp
      def call(env)
        [200, {'Content-Type' => 'text/html'}, ["hello world"]]
      end
    end

    Faraday.new do |conn|
      conn.adapter :rack, MyRackApp.new
    end

### Constants

SPECIAL_HEADERS

  not prefixed with "HTTP_"

### Public Class Methods

new(faraday_app, rack_app) click to toggle source

    # File lib/faraday/adapter/rack.rb, line 22
    def initialize(faraday_app, rack_app)
      super(faraday_app)
      mock_session = ::Rack::MockSession.new(rack_app)
      @session     = ::Rack::Test::Session.new(mock_session)
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/faraday/adapter/rack.rb, line 28
    def call(env)
      super
      rack_env = {
        :method => env[:method],
        :input  => env[:body].respond_to?(:read) ? env[:body].read : env[:body],
        'rack.url_scheme' => env[:url].scheme
      }

      env[:request_headers].each do |name, value|
        name = name.upcase.tr('-', '_')
        name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name
        rack_env[name] = value
      end if env[:request_headers]

      timeout  = env[:request][:timeout] || env[:request][:open_timeout]
      response = if timeout
        Timer.timeout(timeout, Faraday::Error::TimeoutError) { execute_request(env, rack_env) }
      else
        execute_request(env, rack_env)
      end

      save_response(env, response.status, response.body, response.headers)
      @app.call env
    end

execute_request(env, rack_env) click to toggle source

    # File lib/faraday/adapter/rack.rb, line 53
    def execute_request(env, rack_env)
      @session.request(env[:url].to_s, rack_env)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.