Class: Faraday::GetMethodOverride

Inherits:
Middleware
  • Object
show all
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

Constructor Details

#initialize(app, options = nil) ⇒ GetMethodOverride

Public: Initialize the middleware.

app - the Faraday app to wrap



15
16
17
# File 'lib/faraday/get_method_override.rb', line 15

def initialize(app, options = nil)
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/faraday/get_method_override.rb', line 19

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