URI features: naked_domain and subdomain

61 views
Skip to first unread message

Dmitry Rubinstein

unread,
Mar 26, 2017, 5:39:06 AM3/26/17
to elixir-lang-core
Hello!


I want to propose some new features in URI module.

First one is naked domain, which works something like this

assert "http://foo.bar.baz.com" |> URI.parse |> Map.get(:naked_domain) == "baz.com"
or
assert "http://foo.bar.baz.com" |> URI.naked_domain == "baz.com"

And subdomain method:

assert "http://foo.bar.baz.com" |> URI.subdomain("baz.com") == "foo.bar"
assert "http://foo.bar.baz.com" |> URI.subdomain("bar.baz.com") == "foo"

May be it can be relevant.

José Valim

unread,
Mar 26, 2017, 5:46:06 AM3/26/17
to elixir-l...@googlegroups.com
This can be trivially implemented with the existing functionality, so I would recommend defining it in your own apps.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/908c9ab7-321f-43c3-9bdc-8f695f7ebd79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitry Rubinstein

unread,
Mar 26, 2017, 5:48:05 AM3/26/17
to elixir-l...@googlegroups.com
Ok, thank you.
On Sun, 26 Mar 2017 at 12:46 José Valim <jose....@plataformatec.com.br> wrote:
This can be trivially implemented with the existing functionality, so I would recommend defining it in your own apps.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Sun, Mar 26, 2017 at 11:39 AM, Dmitry Rubinstein <rubins...@gmail.com> wrote:
Hello!


I want to propose some new features in URI module.

First one is naked domain, which works something like this

assert "http://foo.bar.baz.com" |> URI.parse |> Map.get(:naked_domain) == "baz.com"
or
assert "http://foo.bar.baz.com" |> URI.naked_domain == "baz.com"

And subdomain method:

assert "http://foo.bar.baz.com" |> URI.subdomain("baz.com") == "foo.bar"
assert "http://foo.bar.baz.com" |> URI.subdomain("bar.baz.com") == "foo"

May be it can be relevant.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/2ncr8joN8Pg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Jz0LXHT-t%3DKZZTBkn1QXdezWNd5rmQYmUZ1DdaJBCFHw%40mail.gmail.com.

Myron Marston

unread,
Mar 26, 2017, 10:42:31 AM3/26/17
to elixir-lang-core
It's not quite clear to me what you mean by "naked domain".  If it's just the last two parts of the fully qualified domain name in the given URI, then yes, it's trivial enough to write a function to get that yourself.  However, many applications are concerned with what the registrable domain is.  For example, from `foo.bar.baz.com` it's `baz.com` but from  `foo.bar.baz.co.uk` it's `baz.co.uk` (the last 3 parts, in this case!).  There's no algorithm for doing this correctly, but mozilla maintains the public suffix list that can be used for this purpose:


We wrote an Elixir library that operates on these rules which you might find useful:


Myron

Dmitry Rubinstein

unread,
Mar 26, 2017, 10:47:29 AM3/26/17
to elixir-lang-core
Yes, thank you.
I know that task is not so trivial, TLD is not so easy problem.
That's why I thought that this functionality probably should be added to the core.
But I watched another languages and solutions and released that because of this list is changing over time - the best solution is to use side library
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/2ncr8joN8Pg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages