     end
   end
 
-  # XXX: should this code be like this? Isn't File module function sufficient?
   defp directory_file_info(path) do
     case :prim_file.read_file_info(path) do
       {:ok, file_info(type: :directory) = file_info} ->

  defp path(from, segments),
    do: Path.join([from|segments])

  defp subset([h|expected], [h|actual]),
    do: subset(expected, actual)
  defp subset([], actual),
    do: actual
  defp subset(_, _),
    do: []

  defp invalid_path?([h|_]) when h in [".", "..", ""], do: true
  defp invalid_path?([h|t]), do: String.contains?(h, ["/", "\\", ":"]) or invalid_path?(t)

    end
  end

  # null directory is allowed here
  defp allowed?(_only, _prefix, nil), do: false
  defp allowed?(_only, _prefix, []), do: true
  defp allowed?([], [], _list), do: true
  defp allowed?(only, prefix, [h|_]) do
    h in only or match?({0, _}, prefix != [] and :binary.match(h, prefix))
  end

  defp serve_directory_listing({:ok, conn, _file_info, path}, at, segments) do
    segments =
      # rewrite null segments to "/"
      case segments do
        [] -> ["/"]
        other -> other
      end
    basepath = Path.join("/", Path.join(Path.join(at), Path.join(segments)))
    conn
    |> put_resp_header("content-type", "text/html")
