Handling invalid UTF-8 strings from URL path params

You could add a plug which checks the :request_path. Something like this:

plug fn (conn, _opts) ->
  if String.valid?(conn.request_path) do
    conn
  else
    conn
    |> Plug.Conn.put_status(:im_a_teapot)
    |> Plug.Conn.halt()
  end
end

This is a quick draft based on the docs. You might want to adjust some parts of it, add some content, make it a module based plug or change the status code sent :smiley:

Also this code assumes, that the :request_path is already decoded at this point. If it is not you can use URI.decode/1 to do so.