boostorg / url

Boost.URL is a library for manipulating Uniform Resource Identifiers (URIs) and Locators (URLs).
https://www.boost.org/doc/libs/master/libs/url/index.html
Boost Software License 1.0
185 stars 50 forks source link

Explore a function to calculate the URL "service" #875

Open alandefreitas opened 1 week ago

alandefreitas commented 1 week ago

This is often calculated as something like:

auto service = url.has_port() ? url.port() : url.scheme();

The term is described in rfc6335 and mentioned in rfc8615 and rfc7595.

In Asio, the async_resolve function returns endpoints that can be directly used for connect operations. The description of the service parameter is:

service A string identifying the requested service. This may be a descriptive name or a numeric string corresponding to a port number. It may be an empty string, in which case all resolved endpoints will have a port number of 0.

There's no concept of ports in a DNS registry, so there is a good chance it is there for users' convenience. Otherwise, users would need to transform the results one more time. It probably uses an OS service to identify the service. It might complete with an error if the service is unknown.

auto service = url.has_port() ? url.port() : url.scheme(); might be good enough for an application with an expectation about what would already be in the URL. But a solution in Boost.URL would be more sophisticated than that: