Skip to content

Commit 8ac921c

Browse files
authored
Optimize Plug.MethodOverride.override_method/2 with direct map pattern match (#1332)
1 parent 05bde70 commit 8ac921c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎lib/plug/method_override.ex‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,15 @@ defmodule Plug.MethodOverride do
5151

5252
def call(%Plug.Conn{} = conn, []), do: conn
5353

54-
defp override_method(conn, %Plug.Conn.Unfetched{}) do
55-
# Just skip it because maybe it is a content-type that
56-
# we could not parse as parameters (for example, text/gps)
57-
conn
58-
end
54+
defp override_method(conn, %{"_method" => method}) when is_binary(method) do
55+
method = String.upcase(method, :ascii)
5956

60-
defp override_method(%Plug.Conn{} = conn, body_params) do
61-
with method when is_binary(method) <- body_params["_method"],
62-
method = String.upcase(method, :ascii),
63-
true <- method in @allowed_methods do
57+
if method in @allowed_methods do
6458
%{conn | method: method}
6559
else
66-
_ -> conn
60+
conn
6761
end
6862
end
63+
64+
defp override_method(conn, _body_params), do: conn
6965
end

0 commit comments

Comments
 (0)