Boost.URL Logo

PrevUpHomeNext

Modifying URLs

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.

Modifiers

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

set_encoded_authority

fragment

set_fragment

set_encoded_fragment

host

set_host

set_encoded_host

password

set_password

set_encoded_password

path

set_path

set_encoded_path

path_absolute

set_path_absolute

set_path_absolute

port

set_port

set_port

query

set_query

set_encoded_query

scheme

set_scheme

set_scheme

user

set_user

set_encoded_user

userinfo

set_userinfo

set_encoded_userinfo

Encoded Modifiers

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.

Decoded Modifiers

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

PrevUpHomeNext