Boost.URL Logo

PrevUpHomeNext

Modifying

Constructing Containers

The class url is a container used to store and produce URLs. The URL parsing functions can be used to create a new container from a url_view:

string_view s = "https://www.example.com";
url_view u = parse_uri(s).value();
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.

Modifiers

The decoded variant of the modifier functions will encode any characters that would be invalid for the specified component.

Code

Output

v.set_host("www.my example.com");
std::cout << v << "\n";
http://www.my%20example.com
v.set_host("my website.com");
v.set_path("my file.txt");
v.set_query("id=42&name=John Doe");
std::cout << v << "\n";
https://my%20website.com/my%20file.txt?id=42&name=John%20Doe
Encoded Modifiers

The encoded variant of the modifier functions require that the encoded strings are valid for the specified component. The functions will throw if the input string contains any character invalid for the specified component.

Code

Output

v.set_scheme("http");
std::cout << v << "\n";
http://www.example.com
Summary

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


PrevUpHomeNext