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 some point, a risk that some countries might resort to implementing alternate DNS roots to get there, which would have seriously fragmented the internet. In the world we live in, a URL is a URL. You can resolve it anywhere in the world (unless your government blocks DNS resolution altogether). In this hypothetical, we would have American URLs and European URLs, or possibly even finer granularity than that, and you would only be able to resolve URLs valid within your country’s system. Some URLs might work internationally, but others might not, and there would be no universal standard, so you’d have to know the recipient’s location to figure out whether the URL is portable. ccTLDs took away most of the motivation for doing that, by giving countries their own little DNS fiefdoms and letting them do whatever they wanted within those fiefdoms (with the understanding that they don’t get to dictate how the rest of the DNS works).
The downside is that, when countries can do whatever they want, they will do whatever they want. So we get co.uk and com.au and all the other arbitrary differences that arise when there are no standards. Incidentally, the very existence of .uk is itself an anomaly, because the official ccTLD for the UK is “supposed” to be .gb. The UK had already implemented a pre-DNS naming scheme with uk at the top level, and the ISO code uk is permanently reserved to avoid confusion (meaning there’s no risk of .uk conflicting with some other country, either now or in the future), so they were allowed to keep it. It’s fortunate that uk was already reserved by ISO – if it had been allocated to e.g. Ukraine, then the geopolitics would have been complicated and probably unpleasant (the ISO list was not designed for internet use – it was designed for postal use, so they probably wouldn’t be happy with revising the list just because IANA painted itself into a corner).
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.