The Windows Runtime class Windows.
has two string properties: Host
and Domain
. What’s the difference?
Let’s start with Host
. This is the “host” as defined in RFC 3986 which defines the syntax for URIs.
Okay, that was easy. What about Domain
?
The Domain
is an attempt to identify the part of the Host
that was registered with a top-level domain (TLD) registrar.
Host | Domain |
---|---|
example.com | example.com |
mail.example.com | example.com |
www.bbc.co.uk | bbc.co.uk |
bbc.co.uk | bbc.co.uk |
The code for the Domain
property applies a bunch of rules to determine how many levels of the fully-qualified domain name should be used to determine the “domain”.
The problem is that the authority for these rules is “whoever runs the TLD”. We see that different TLDs have different policies: The .com TLD allows organizations to register second-level domains, whereas the .uk TLD registers organizations as third-level domains, under .co.uk. There is no standard for how each TLD assigns its domains; each TLD can choose whatever pattern it likes.
What’s more, there’s no requirement that a TLD stick to the pattern it chose originally, or even have a pattern at all. For example, the .br TLD (waves hello in Brazilian Portuguese) originally registered organizations under the third level, so you got names like contoso.com.br, but it then decided to allow organizations (primarily universities) to register as second-level domains. This means that if you are given a domain under .br, you have to look at the second-level domain and see if it’s on a list of known reserved second-level domains such as com.br for commercial organizations or slg.br for (checks notes) sociologists. If so, then the third-level domain is the organizational domain; otherwise, you have an organization that was granted a second-level domain.
There are over 100 defined reserved second-level domains under .br, and I suspect that the list has grown even longer while I was sleeping. It’s practically impossible to keep up with all of these changes in TLD policy around the world, so what you get from the Domain
property is a best-guess at the organizational domain. And at least for the .br TLD, it’s definitely not completely up to date. For example, it thinks that the organizational domain for mail.contoso.tec.br is tec.br instead of contoso.tec.br.
So what is Domain
good for?
I’m not sure. It’s trying its best, but the world is too complicated.
The Public Suffix List is meant to track such things. I wonder if
Domain
uses that list (albeit an outdated version).For the same reason the Public Suffix List was created, correct? Couldn’t it maybe retrofitted to use a snapshot of the PSL under the scenes?
ccTLDs are basically a mess. Unfortunately, it's a case of the technology reflecting messy reality, rather than something you can "just fix." Governments want to administer their own domains, for various administrative and political reasons that range from "we don't want our citizens getting scammed by fake government websites" to "if the US government can have .gov and .mil, then we should be allowed to have our own official domains too." There was probably, at...
So my initial thought would be that ‘Domain’ is intended to match the web ‘same site’ definition, which uses the Public Suffix List (PSL).
But if that was the case, I would also expect it to get regularly synced with the official list. Which most obviously isn’t the case here, since tec.br was added as a new official SLD in July-2020 !!
There is a Mozilla’s Public Suffix List project specifically for this purpose. On Linux it is typically used via libpsl C library, with the list itself updated separately system-wide, so that applications won’t need to bundle it.
A better question would be “why was Domain created?”
I’m guessing code for the Windows Runtime is not added just because a dev felt like it.