Sha256: e9e0a1578c447af27f08d9fd767ce1408f54e556a1727d93831dae5860f3f411

Contents?: true

Size: 774 Bytes

Versions: 42

Compression:

Stored size: 774 Bytes

Contents

module Rack
  class MethodOverride
    HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS PATCH)

    METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
    HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze

    def initialize(app)
      @app = app
    end

    def call(env)
      if env["REQUEST_METHOD"] == "POST"
        method = method_override(env)
        if HTTP_METHODS.include?(method)
          env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
          env["REQUEST_METHOD"] = method
        end
      end

      @app.call(env)
    end

    def method_override(env)
      req = Request.new(env)
      method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
        env[HTTP_METHOD_OVERRIDE_HEADER]
      method.to_s.upcase
    end
  end
end

Version data entries

42 entries across 37 versions & 11 rubygems

Version Path
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/rack-1.5.5/lib/rack/methodoverride.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/rack-1.5.5/lib/rack/methodoverride.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/rack-1.5.5/lib/rack/methodoverride.rb
rack-1.5.5 lib/rack/methodoverride.rb
rack-1.5.4 lib/rack/methodoverride.rb
rack-1.5.3 lib/rack/methodoverride.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.5 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.4 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.3 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.3.pre lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.2 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.1 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-1.0.0 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb
scout_realtime-0.5.5 lib/vendor/rack-1.5.2/lib/rack/methodoverride.rb