aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-08-16 19:16:00 +0200
committerMelonai <einebeere@gmail.com>2021-08-16 19:16:00 +0200
commite81c9eb128001bfa9512a29e41a61d77a20e1050 (patch)
tree8ce0f484b9a370174fec5f7795b0cf0090d412f6 /lib
parenta7af012b92f0dfd90cc3eb570e03144016646180 (diff)
downloadrook-e81c9eb128001bfa9512a29e41a61d77a20e1050.tar.zst
rook-e81c9eb128001bfa9512a29e41a61d77a20e1050.zip
Parse user agent
Diffstat (limited to 'lib')
-rw-r--r--lib/rook/application.ex4
-rw-r--r--lib/rook/utils/identity.ex26
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/rook/application.ex b/lib/rook/application.ex
index 537fe70..2d71798 100644
--- a/lib/rook/application.ex
+++ b/lib/rook/application.ex
@@ -16,7 +16,9 @@ defmodule Rook.Application do
# Start a worker by calling: Rook.Worker.start_link(arg)
# {Rook.Worker, arg}
{Registry, keys: :unique, name: Registry.Share},
- {Registry, keys: :unique, name: Registry.Request}
+ {Registry, keys: :unique, name: Registry.Request},
+
+ UAInspector.Supervisor,
]
# See https://hexdocs.pm/elixir/Supervisor.html
diff --git a/lib/rook/utils/identity.ex b/lib/rook/utils/identity.ex
index 82fb7d9..385030e 100644
--- a/lib/rook/utils/identity.ex
+++ b/lib/rook/utils/identity.ex
@@ -9,8 +9,30 @@ defmodule Rook.Identity do
end
def get_client_from_user_agent(user_agent) do
- # TODO: Parse user agent to get client
- "Unknown Client"
+ ua = UAInspector.parse_client(user_agent)
+
+ if ua.client != nil do
+ browser_family = ua.client.name
+ browser_version = ua.client.version
+
+ browser = if browser_family != :unknown do
+ if browser_version != :unknown do
+ browser_family <> " " <> browser_version
+ else
+ browser_family
+ end
+ else
+ "Unknown Browser"
+ end
+
+ if ua.os_family != :unknown do
+ browser <> " on " <> ua.os_family
+ else
+ browser
+ end
+ else
+ "Unknown Client"
+ end
end
defp ip_to_string(ip) do