Class: Rack::MethodOverride
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rack/method_override.rb |
Constant Summary
-
ALLOWED_METHODS =
# File 'lib/rack/method_override.rb', line 13%w[POST]
-
HTTP_METHODS =
# File 'lib/rack/method_override.rb', line 9%w[GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK]
-
HTTP_METHOD_OVERRIDE_HEADER =
# File 'lib/rack/method_override.rb', line 12"HTTP_X_HTTP_METHOD_OVERRIDE"
-
METHOD_OVERRIDE_PARAM_KEY =
# File 'lib/rack/method_override.rb', line 11"_method"
Class Method Summary
- .new(app) ⇒ MethodOverride constructor
Instance Method Summary
- #call(env)
- #method_override(env)
- #allowed_methods private
- #method_override_param(req) private
Constructor Details
.new(app) ⇒ MethodOverride
# File 'lib/rack/method_override.rb', line 15
def initialize(app) @app = app end
Instance Method Details
#allowed_methods (private)
[ GitHub ]# File 'lib/rack/method_override.rb', line 44
def allowed_methods ALLOWED_METHODS end
#call(env)
[ GitHub ]# File 'lib/rack/method_override.rb', line 19
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)
[ GitHub ]# File 'lib/rack/method_override.rb', line 31
def method_override(env) req = Request.new(env) method = method_override_param(req) || env[HTTP_METHOD_OVERRIDE_HEADER] begin method.to_s.upcase rescue ArgumentError env[RACK_ERRORS].puts "Invalid string for method" end end
#method_override_param(req) (private)
[ GitHub ]# File 'lib/rack/method_override.rb', line 48
def method_override_param(req) req.POST[METHOD_OVERRIDE_PARAM_KEY] if req.form_data? || req.parseable_data? rescue Utils::InvalidParameterError, Utils::ParameterTypeError, QueryParser::ParamsTooDeepError req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params" rescue EOFError req.get_header(RACK_ERRORS).puts "Bad request content body" end