diff --git a/lib/phx_tools_web/plugs/curl_detector.ex b/lib/phx_tools_web/plugs/curl_detector.ex index 28eb033c..a4e704e8 100644 --- a/lib/phx_tools_web/plugs/curl_detector.ex +++ b/lib/phx_tools_web/plugs/curl_detector.ex @@ -27,8 +27,8 @@ defmodule PhxToolsWeb.CurlDetector do end end - defp request_sent_from_curl?(nil), do: false - defp request_sent_from_curl?(user_agent), do: String.starts_with?(user_agent, "curl") + defp request_sent_from_curl?("curl" <> _rest), do: true + defp request_sent_from_curl?(_user_agent), do: false defp script_content do :phx_tools diff --git a/test/phx_tools_web/plugs/curl_detector_test.exs b/test/phx_tools_web/plugs/curl_detector_test.exs index 8aa774b3..c2426ffa 100644 --- a/test/phx_tools_web/plugs/curl_detector_test.exs +++ b/test/phx_tools_web/plugs/curl_detector_test.exs @@ -44,5 +44,10 @@ defmodule PhxToolsWeb.CurlDetectorTest do assert conn.status == 200 assert String.contains?(conn.resp_body, @script_content) end + + test "doesn't crash when User-Agent is nil", %{conn: conn} do + conn = get(conn, "/") + assert conn.status == 200 + end end end