aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/verb_piggybacking.rb
blob: 86cde304a0b0120111dc933aa69e4df286579045 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module ActionController
  # TODO: Use Rack::MethodOverride when it is released
  class VerbPiggybacking
    HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)

    def initialize(app)
      @app = app
    end

    def call(env)
      if env["REQUEST_METHOD"] == "POST"
        req = Request.new(env)
        if method = (req.parameters[:_method] || env["HTTP_X_HTTP_METHOD_OVERRIDE"])
          method = method.to_s.upcase
          if HTTP_METHODS.include?(method)
            env["REQUEST_METHOD"] = method
          end
        end
      end

      @app.call(env)
    end
  end
end