// https://www.boost.org/doc/libs/1_92_0/libs/url/doc/html/url/urls/containers.html

#include <boost/url.hpp>

#include <cassert>
#include <iostream>

int main()
{
    // Build a URL piece by piece
    boost::urls::url u;
    u.set_scheme("https");
    u.set_encoded_host("www.debian.org");
    u.set_encoded_path("/distrib/packages");
    u.params().append({ "keywords", "boost c++" });

    std::cout << "built    = " << u << std::endl;
    assert(u.buffer() == "https://www.debian.org/distrib/packages?keywords=boost+c%2B%2B");

    // Percent-encoded values are decoded back to the original string
    assert((*u.params().find("keywords")).value == "boost c++");

    // Resolving a relative reference against a base
    boost::urls::url_view base = boost::urls::parse_uri("https://www.debian.org/a/b/c").value();
    boost::urls::url_view ref = boost::urls::parse_uri_reference("../d").value();

    boost::urls::url resolved;
    boost::system::result<void> rv = boost::urls::resolve(base, ref, resolved);
    assert(!rv.has_error());

    std::cout << "resolved = " << resolved << std::endl;
    assert(resolved.buffer() == "https://www.debian.org/a/d");

    // Normalisation removes dot segments
    boost::urls::url n = boost::urls::parse_uri("https://www.debian.org/a/./b/../c").value();
    n.normalize();
    std::cout << "normal   = " << n << std::endl;
    assert(n.buffer() == "https://www.debian.org/a/c");

    return 0;
}
