Sha256: b73a3f746c0de95c9b0ea470cab7b9d7ea3b31f4385e88d8a4af65c4095784dd

Contents?: true

Size: 709 Bytes

Versions: 69

Compression:

Stored size: 709 Bytes

Contents

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

    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"
        req = Request.new(env)
        method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
          env[HTTP_METHOD_OVERRIDE_HEADER]
        method = method.to_s.upcase
        if HTTP_METHODS.include?(method)
          env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
          env["REQUEST_METHOD"] = method
        end
      end

      @app.call(env)
    end
  end
end

Version data entries

69 entries across 68 versions & 21 rubygems

Version Path
kjvarga-rack-1.0.0 lib/rack/methodoverride.rb
p8-castronaut-0.6.1.1 vendor/rack/lib/rack/methodoverride.rb
qoobaa-rack-1.0.0.1 lib/rack/methodoverride.rb
qoobaa-rack-1.0.2 lib/rack/methodoverride.rb
relevance-castronaut-0.6.0 vendor/rack/lib/rack/methodoverride.rb
relevance-castronaut-0.6.1 vendor/rack/lib/rack/methodoverride.rb
relevance-castronaut-0.7.4 vendor/rack/lib/rack/methodoverride.rb
relevance-castronaut-0.7.5 vendor/rack/lib/rack/methodoverride.rb
timocratic-rack-1.0.0 lib/rack/methodoverride.rb
rack-1.2.8 lib/rack/methodoverride.rb
rack-1.1.6 lib/rack/methodoverride.rb
rack-1.2.7 lib/rack/methodoverride.rb
rack-1.1.5 lib/rack/methodoverride.rb
rack-1.2.6 lib/rack/methodoverride.rb
rack-1.1.4 lib/rack/methodoverride.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/lib/rack/methodoverride.rb
rack-1.2.5 lib/rack/methodoverride.rb
rack-1.1.3 lib/rack/methodoverride.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/lib/rack/methodoverride.rb
rack-1.2.4 lib/rack/methodoverride.rb