Class: Faraday::GetMethodOverride
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::GetMethodOverride
- Defined in:
- lib/faraday/get_method_override.rb
Overview
Public: Writes the original HTTP method to “X-Http-Method-Override” header and sends the request as POST for GET requests that are too long.
Constant Summary collapse
- HEADER =
'X-Http-Method-Override'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _options = nil) ⇒ GetMethodOverride
constructor
Public: Initialize the middleware.
Constructor Details
#initialize(app, _options = nil) ⇒ GetMethodOverride
Public: Initialize the middleware.
app - the Faraday app to wrap
13 14 15 |
# File 'lib/faraday/get_method_override.rb', line 13 def initialize(app, = nil) super(app) end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/faraday/get_method_override.rb', line 17 def call(env) if env[:method] == :get && env[:url].to_s.size > 2000 env[:request_headers][HEADER] = 'GET' env[:request_headers]['Content-Type'] = 'application/x-www-form-urlencoded' env[:body] = env[:url].query env[:url].query = nil env[:method] = :post end @app.call(env) end |