From 08560ed716fd818bfd7e28dfb4b3d237b08a86d8 Mon Sep 17 00:00:00 2001 From: preciz Date: Wed, 21 Oct 2026 09:48:02 +0200 Subject: [PATCH] Optimize Plug.MethodOverride.override_method/2 with direct map pattern match --- lib/plug/method_override.ex | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/plug/method_override.ex b/lib/plug/method_override.ex index cb96b7d0e..3fa6d66ed 100644 --- a/lib/plug/method_override.ex +++ b/lib/plug/method_override.ex @@ -51,19 +51,15 @@ defmodule Plug.MethodOverride do def call(%Plug.Conn{} = conn, []), do: conn - defp override_method(conn, %Plug.Conn.Unfetched{}) do - # Just skip it because maybe it is a content-type that - # we could not parse as parameters (for example, text/gps) - conn - end + defp override_method(conn, %{"_method" => method}) when is_binary(method) do + method = String.upcase(method, :ascii) - defp override_method(%Plug.Conn{} = conn, body_params) do - with method when is_binary(method) <- body_params["_method"], - method = String.upcase(method, :ascii), - true <- method in @allowed_methods do + if method in @allowed_methods do %{conn | method: method} else - _ -> conn + conn end end + + defp override_method(conn, _body_params), do: conn end