Sha256: 1be0cb32c271ce1562a0be2ef7c52c7eacdc7b41899ee7c03e0433acb82a1545

Contents?: true

Size: 803 Bytes

Versions: 161

Compression:

Stored size: 803 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
    rescue EOFError
      ""
    end
  end
end

Version data entries

161 entries across 137 versions & 24 rubygems

Version Path
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-rolls-0.1.0 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-0.8.0.pre vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-0.7.1 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.10 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.9 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-0.7.0 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-0.7.0.pre2 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
bitclust-core-0.5.1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.8 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.7 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.6 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.5 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
challah-0.7.0.pre vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb
classiccms-0.5.2 vendor/bundle/gems/rack-1.4.1/lib/rack/methodoverride.rb