Boost URL implements general purpose URIs. Not all URIs contain fully-qualified domain names. As such, parsing the scheme-dependent parts of the authority are mostly out of scope for the library.
However since internet addresses are ubiquitous in network URIs (ftp, ssh, sftp, http, etc) some support is there, and you might at least use that to your advantage to avoid misinterpreting information as if they were domain names:
As an example test bed:
Live On Coliru1
#include <boost/url.hpp>
#include <iostream>
int main () {
for (auto txt : {
// explicit port
"https://my.pretty.sub.domain.com:8989/path/to/resource?stuff=more&stuff#end",
"https://my.com:8989/path/to/resource?stuff=more&stuff#end",
"https://localhost:8989/path/to/resource?stuff=more&stuff#end",
"https://[::1]:8989/path/to/resource?stuff=more&stuff#end",
"https://127.0.0.1:8989/path/to/resource?stuff=more&stuff#end",
// without port
"https://my.pretty.sub.domain.com/path/to/resource?stuff=more&stuff#end",
"https://my.com/path/to/resource?stuff=more&stuff#end",
"https://localhost/path/to/resource?stuff=more&stuff#end",
"https://[::1]/path/to/resource?stuff=more&stuff#end",
"https://127.0.0.1/path/to/resource?stuff=more&stuff#end",
}) {
if (auto parsed = boost::urls::parse_uri(txt); parsed && parsed->has_authority()) {
auto url = parsed.value();
switch (url.host_type ())
{
case boost::urls::host_type::ipv4:
case boost::urls::host_type::ipv6:
case boost::urls::host_type::ipvfuture:
case boost::urls::host_type::none:
std::cerr << "adress or none: '" << url.host () << "'\n";
break;
case boost::urls::host_type::name:
std::cout << "maybe FQDN: '" << url.host_name () << "'\n";
break;
}
}
}
}
Printing
maybe FQDN: 'my.pretty.sub.domain.com'
maybe FQDN: 'my.com'
maybe FQDN: 'localhost'
adress or none: '[::1]'
adress or none: '127.0.0.1'
maybe FQDN: 'my.pretty.sub.domain.com'
maybe FQDN: 'my.com'
maybe FQDN: 'localhost'
adress or none: '[::1]'
adress or none: '127.0.0.1'
1 note: coliru sadly doesn’t let me share it because it triggers spam detection with the urls. But the output can be seen there if you just copy paste and build g++ -std=c++20 -O2 -Wall -pedantic -pthread main.cpp -lboost_url && ./a.out