 defmodule WebbkollWeb.Plugs do
-  #use Phoenix.Controller, namespace: WebbkollWeb
-
   import Plug.Conn
   import WebbkollWeb.Gettext
 

        false -> "http://#{conn.params["url"]}" |> URI.parse() |> get_proper_url()
      end

    assign(conn, :input_url, url)
  end

  def check_rate_ip(conn, _params) do

  def check_user_agent([], conn), do: conn

  def get_proper_url(url = %URI{}) do
    # :idna.utf8_to_ascii() exits on invalid input, so here's a fugly workaround.
    try do
      case @validate_urls do
        true ->
          URI.to_string(%URI{
            host: url.host |> :idna.utf8_to_ascii() |> List.to_string() |> String.downcase(),
            path: url.path,
            query: url.query,
            scheme: "http"
          })

        false ->
          URI.to_string(%URI{
            host: url.host |> :idna.utf8_to_ascii() |> List.to_string() |> String.downcase(),
            path: url.path,
            query: url.query,
            scheme: "http",
            port: url.port,
          })
      end
    catch
      :exit, {:bad_label, _} -> nil
    end
  end

