mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add docs to Kemal::OverrideMethodHandler
This commit is contained in:
parent
3f7c8b4577
commit
a60168d039
1 changed files with 11 additions and 2 deletions
|
@ -1,4 +1,13 @@
|
|||
module Kemal
|
||||
# Adds support for `_method` magic parameter to simulate PUT, PATCH, DELETE requests in an html form.
|
||||
#
|
||||
# This middleware is **not** in the default Kemal handlers. You need to explicitly add this to your handlers:
|
||||
#
|
||||
# ```ruby
|
||||
# add_handler Kemal::OverrideMethodHandler
|
||||
# ```
|
||||
#
|
||||
# **Important:** This middleware consumes `params.body` to read the `_method` magic parameter.
|
||||
class OverrideMethodHandler
|
||||
include HTTP::Handler
|
||||
INSTANCE = new
|
||||
|
@ -10,14 +19,14 @@ module Kemal
|
|||
def call(context)
|
||||
request = context.request
|
||||
if request.method == OVERRIDE_METHOD
|
||||
if context.params.body.has_key?(OVERRIDE_METHOD_PARAM_KEY) && override_method_valid?(context.params.body["_method"])
|
||||
if context.params.body.has_key?(OVERRIDE_METHOD_PARAM_KEY) && override_method_valid?(context.params.body[OVERRIDE_METHOD_PARAM_KEY])
|
||||
request.method = context.params.body["_method"].upcase
|
||||
end
|
||||
end
|
||||
call_next(context)
|
||||
end
|
||||
|
||||
def override_method_valid?(override_method : String)
|
||||
private def override_method_valid?(override_method : String)
|
||||
ALLOWED_METHODS.includes?(override_method.upcase)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue