2 class Request::UrlEncoded < Faraday::Middleware
3 CONTENT_TYPE = 'Content-Type'.freeze unless defined? CONTENT_TYPE
6 attr_accessor :mime_type
8 self.mime_type = 'application/x-www-form-urlencoded'.freeze
11 match_content_type(env) do |data|
12 params = Faraday::Utils::ParamsHash[data]
13 env.body = params.to_query(env.params_encoder)
18 def match_content_type(env)
19 if process_request?(env)
20 env.request_headers[CONTENT_TYPE] ||= self.class.mime_type
21 yield(env.body) unless env.body.respond_to?(:to_str)
25 def process_request?(env)
26 type = request_type(env)
27 env.body and (type.empty? or type == self.class.mime_type)
31 type = env.request_headers[CONTENT_TYPE].to_s
32 type = type.split(';', 2).first if type.index(';')