Faraday::Middleware
Public: Writes the original HTTP method to “X-Http-Method-Override” header and sends the request as POST.
This can be used to work around technical issues with making non-POST requests, e.g. faulty HTTP client or server router.
This header is recognized in Rack apps by default, courtesy of the Rack::MethodOverride module. See rack.rubyforge.org/doc/classes/Rack/MethodOverride.html
Public: Initialize the middleware.
app - the Faraday app to wrap options - (optional)
:rewrite - Array of HTTP methods to rewrite (default: all but GET and POST)
# File lib/faraday_middleware/request/method_override.rb, line 23 def initialize(app, options = nil) super(app) @methods = options && options.fetch(:rewrite).map { |method| method = method.downcase if method.respond_to? :downcase method.to_sym } end
# File lib/faraday_middleware/request/method_override.rb, line 31 def call(env) method = env[:method] rewrite_request(env, method) if rewrite_request?(method) @app.call(env) end
Internal: Write the original HTTP method to header, change method to POST.
# File lib/faraday_middleware/request/method_override.rb, line 46 def rewrite_request(env, original_method) env[:request_headers][HEADER] = original_method.to_s.upcase env[:method] = :post end
Generated with the Darkfish Rdoc Generator 2.