class Faraday::GetMethodOverride

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.

Constants

Public Class Methods

new(app, options = nil) click to toggle source

Public: Initialize the middleware.

app - the Faraday app to wrap

Calls superclass method
# File lib/faraday/get_method_override.rb, line 14
def initialize(app, options = nil)
  super(app)
end

Public Instance Methods

call(env) click to toggle source
# File lib/faraday/get_method_override.rb, line 18
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