Sha256: 1bc367270a08e97e6cc55329c8eaf036ddb8df24cee1e71833eee8ba3268c1ba

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

module Faraday
  class Adapter < Middleware
    CONTENT_LENGTH = 'Content-Length'.freeze

    extend AutoloadHelper
    extend MiddlewareRegistry

    autoload_all 'faraday/adapter',
      :NetHttp           => 'net_http',
      :NetHttpPersistent => 'net_http_persistent',
      :Typhoeus          => 'typhoeus',
      :EMSynchrony       => 'em_synchrony',
      :EMHttp            => 'em_http',
      :Patron            => 'patron',
      :Excon             => 'excon',
      :Test              => 'test',
      :Rack              => 'rack'

    register_middleware \
      :test                => :Test,
      :net_http            => :NetHttp,
      :net_http_persistent => :NetHttpPersistent,
      :typhoeus            => :Typhoeus,
      :patron              => :Patron,
      :em_synchrony        => :EMSynchrony,
      :em_http             => :EMHttp,
      :excon               => :Excon,
      :rack                => :Rack

    module Parallelism
      attr_writer :supports_parallel
      def supports_parallel?() @supports_parallel end

      def inherited(subclass)
        super
        subclass.supports_parallel = self.supports_parallel?
      end
    end

    extend Parallelism
    self.supports_parallel = false

    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

    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
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
faraday-0.8.11 lib/faraday/adapter.rb
faraday-0.8.10 lib/faraday/adapter.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/faraday-0.8.9/lib/faraday/adapter.rb
faraday-0.8.9 lib/faraday/adapter.rb
faraday-0.8.8 lib/faraday/adapter.rb
faraday-0.8.7 lib/faraday/adapter.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/faraday-0.8.6/lib/faraday/adapter.rb
faraday-0.8.6 lib/faraday/adapter.rb
faraday-0.8.5 lib/faraday/adapter.rb
faraday-0.8.4 lib/faraday/adapter.rb
faraday-0.8.2 lib/faraday/adapter.rb
faraday-0.8.1 lib/faraday/adapter.rb
faraday-0.8.0 lib/faraday/adapter.rb