Sha256: 0d80785ac6c6467d41d04bece500f2cdd3da71d6c7bad27e9331e51eecc0e99f

Contents?: true

Size: 1.61 KB

Versions: 85

Compression:

Stored size: 1.61 KB

Contents

module Faraday
  class Adapter
    # 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
    class Rack < Faraday::Adapter
      dependency 'rack/test'

      # not prefixed with "HTTP_"
      SPECIAL_HEADERS = %w[ CONTENT_LENGTH CONTENT_TYPE ]

      def initialize(faraday_app, rack_app)
        super(faraday_app)
        mock_session = ::Rack::MockSession.new(rack_app)
        @session     = ::Rack::Test::Session.new(mock_session)
      end

      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

      def execute_request(env, rack_env)
        @session.request(env[:url].to_s, rack_env)
      end
    end
  end
end

Version data entries

85 entries across 78 versions & 10 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/faraday-0.17.0/lib/faraday/adapter/rack.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/faraday-0.17.0/lib/faraday/adapter/rack.rb
faraday-0.17.0 lib/faraday/adapter/rack.rb
tdiary-5.0.13 vendor/bundle/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
tdiary-5.0.12.1 vendor/bundle/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
tdiary-5.0.11 vendor/bundle/gems/faraday-0.15.4/lib/faraday/adapter/rack.rb
tdiary-5.0.11 vendor/bundle/gems/faraday-0.15.3/lib/faraday/adapter/rack.rb
tdiary-5.0.11 vendor/bundle/gems/faraday-0.15.2/lib/faraday/adapter/rack.rb
faraday-0.15.4 lib/faraday/adapter/rack.rb
faraday-0.15.3 lib/faraday/adapter/rack.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/faraday-0.15.2/lib/faraday/adapter/rack.rb
tdiary-5.0.9 vendor/bundle/gems/faraday-0.15.1/lib/faraday/adapter/rack.rb