Class: Faraday::Request::UrlEncoded
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::UrlEncoded
- Defined in:
- lib/faraday/request/url_encoded.rb
Direct Known Subclasses
Constant Summary collapse
- CONTENT_TYPE =
'Content-Type'.freeze
Class Attribute Summary collapse
-
.mime_type ⇒ Object
Returns the value of attribute mime_type.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #match_content_type(env) ⇒ Object
- #process_request?(env) ⇒ Boolean
- #request_type(env) ⇒ Object
Methods inherited from Middleware
adapter?, dependency, inherited, #initialize, loaded?, new
Methods included from MiddlewareRegistry
#lookup_middleware, #register_middleware
Constructor Details
This class inherits a constructor from Faraday::Middleware
Class Attribute Details
.mime_type ⇒ Object
Returns the value of attribute mime_type.
6 7 8 |
# File 'lib/faraday/request/url_encoded.rb', line 6 def mime_type @mime_type end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/faraday/request/url_encoded.rb', line 10 def call(env) match_content_type(env) do |data| env[:body] = Faraday::Utils.build_nested_query data end @app.call env end |
#match_content_type(env) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/faraday/request/url_encoded.rb', line 17 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 |
#process_request?(env) ⇒ Boolean
24 25 26 27 |
# File 'lib/faraday/request/url_encoded.rb', line 24 def process_request?(env) type = request_type(env) env[:body] and (type.empty? or type == self.class.mime_type) end |
#request_type(env) ⇒ Object
29 30 31 32 33 |
# File 'lib/faraday/request/url_encoded.rb', line 29 def request_type(env) type = env[:request_headers][CONTENT_TYPE].to_s type = type.split(';', 2).first if type.index(';') type end |