Skip to content

Commit

Permalink
Do it the Elixir-way
Browse files Browse the repository at this point in the history
  • Loading branch information
almirsarajcic committed Nov 15, 2024
1 parent ae4a0c1 commit a515b08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/phx_tools_web/plugs/curl_detector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/phx_tools_web/plugs/curl_detector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a515b08

Please sign in to comment.