Sha256: 27a86760a85fb64db582ff80321db5f48e6b083a7e7d2e408ad181931f2094a9

Contents?: true

Size: 969 Bytes

Versions: 88

Compression:

Stored size: 969 Bytes

Contents

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

    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|
        params = Faraday::Utils::ParamsHash[data]
        env.body = params.to_query(env.params_encoder)
      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

88 entries across 80 versions & 10 rubygems

Version Path
faraday-0.17.6 lib/faraday/request/url_encoded.rb
faraday-0.17.5 lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/url_encoded.rb