The class url
is a container used to store and produce URLs. The URL
parsing functions can be used to create a new container:
urls::string_view s = "https://www.example.com"; urls::url_view u = urls::parse_uri(s).value(); urls::url v(u);
All url_view
observers are also available for a url
:
std::cout << v << "\n" "scheme: " << v.scheme() << "\n" "has authority: " << v.has_authority() << "\n" "authority: " << v.encoded_authority() << "\n" "path: " << v.encoded_path() << "\n";
The interface of url_view
decomposes the URL into its
individual parts and allows for inspection of the various parts as well as
returning metadata about the URL itself. These non-modifying observer operations
are described in the sections that follow.
For each observer function in url_view
, an instance of url
provides a corresponding set
function to define the value of the specified
component.
Component |
Decoded |
Encoded |
---|---|---|
authority |
||
fragment |
||
host |
||
password |
||
path |
||
path_absolute |
||
port |
||
query |
||
scheme |
||
user |
||
userinfo |
The encoded modifier functions require that the encoded strings are valid for the specified component.
Code |
Output |
---|---|
v.set_scheme("http"); std::cout << v << "\n"; |
http://www.example.com |
If the input string contains an invalid value, an exception is thrown.
The decoded modifier functions will encode any input string that is invalid as
Code |
Output |
---|---|
v.set_host("www.my example.com"); std::cout << v << "\n"; |
http://www.my%20example.com |