Sha256: def469d93fd6fdafe45a510325722b2b014a0ed2d85aa5dd3338798ef9daf439

Contents?: true

Size: 904 Bytes

Versions: 16

Compression:

Stored size: 904 Bytes

Contents

module Faraday
  class Request::UrlEncoded < Faraday::Middleware
    CONTENT_TYPE = 'Content-Type'.freeze

    class << self
      attr_accessor :mime_type
    end
    self.mime_type = 'application/x-www-form-urlencoded'.freeze

    def call(env)
      match_content_type(env) do |data|
        env[:body] = Faraday::Utils.build_nested_query data
      end
      @app.call env
    end

    def match_content_type(env)
      if process_request?(env)
        env[:request_headers][CONTENT_TYPE] ||= self.class.mime_type
        yield env[:body] unless env[:body].respond_to?(:to_str)
      end
    end

    def process_request?(env)
      type = request_type(env)
      env[:body] and (type.empty? or type == self.class.mime_type)
    end

    def request_type(env)
      type = env[:request_headers][CONTENT_TYPE].to_s
      type = type.split(';', 2).first if type.index(';')
      type
    end
  end
end

Version data entries

16 entries across 16 versions & 4 rubygems

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