class Rack::MethodOverride - rack-1.6.4 Documentation

# class Rack::MethodOverride

### Constants

ALLOWED_METHODS
HTTP_METHODS
HTTP_METHOD_OVERRIDE_HEADER
METHOD_OVERRIDE_PARAM_KEY

### Public Class Methods

new(app) click to toggle source

    # File lib/rack/methodoverride.rb, line 9
    def initialize(app)
      @app = app
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/rack/methodoverride.rb, line 13
    def call(env)
      if allowed_methods.include?(env[REQUEST_METHOD])
        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

method_override(env) click to toggle source

    # File lib/rack/methodoverride.rb, line 25
    def method_override(env)
      req = Request.new(env)
      method = method_override_param(req) ||
        env[HTTP_METHOD_OVERRIDE_HEADER]
      method.to_s.upcase
    end

### Private Instance Methods

allowed_methods() click to toggle source

    # File lib/rack/methodoverride.rb, line 34
    def allowed_methods
      ALLOWED_METHODS
    end

method_override_param(req) click to toggle source

    # File lib/rack/methodoverride.rb, line 38
    def method_override_param(req)
      req.POST[METHOD_OVERRIDE_PARAM_KEY]
    rescue Utils::InvalidParameterError, Utils::ParameterTypeError
    end