Class: Sinja::MethodOverride

Inherits:
Object
  • Object
show all
Defined in:
lib/sinja/method_override.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ MethodOverride

Returns a new instance of MethodOverride.


4
5
6
# File 'lib/sinja/method_override.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/sinja/method_override.rb', line 8

def call(env)
  env['REQUEST_METHOD'] = env['HTTP_X_HTTP_METHOD_OVERRIDE'] \
    if env.key?('HTTP_X_HTTP_METHOD_OVERRIDE') \
      && env['REQUEST_METHOD'] == 'POST' \
      && env['HTTP_X_HTTP_METHOD_OVERRIDE'].tap(&:upcase!) == 'PATCH'

  @app.call(env)
end