From 1d1692267ce3d4fd87bdbe8823f30f9119e68abd Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Tue, 3 Sep 2019 12:47:06 +0200 Subject: [PATCH] Fully support PATCH like PUT and DELETE. --- spec/http_method_override_handler_spec.cr | 3 ++- src/lucky/http_method_override_handler.cr | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/http_method_override_handler_spec.cr b/spec/http_method_override_handler_spec.cr index ba8056edd..303e296ea 100644 --- a/spec/http_method_override_handler_spec.cr +++ b/spec/http_method_override_handler_spec.cr @@ -9,7 +9,8 @@ describe Lucky::HttpMethodOverrideHandler do should_handle "POST", overridden_method: "", and_return: "POST" end - it "overrides when POST with overridden PUT or DELETE" do + it "overrides when POST with overridden PATCH, PUT or DELETE" do + should_handle "POST", overridden_method: "patch", and_return: "PATCH" should_handle "POST", overridden_method: "put", and_return: "PUT" should_handle "POST", overridden_method: "delete", and_return: "DELETE" end diff --git a/src/lucky/http_method_override_handler.cr b/src/lucky/http_method_override_handler.cr index 6503e6a41..c9377215a 100644 --- a/src/lucky/http_method_override_handler.cr +++ b/src/lucky/http_method_override_handler.cr @@ -12,7 +12,7 @@ class Lucky::HttpMethodOverrideHandler end private def override_allowed?(context, http_method) : Bool - ["POST"].includes?(context.request.method) && ["PUT", "DELETE"].includes?(http_method) + ["POST"].includes?(context.request.method) && ["PATCH", "PUT", "DELETE"].includes?(http_method) end private def overridden_http_method(context) : String?