Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit d7c8a7cf0d.
PrevUpHomeNext

resolve

Resolve a URL reference against a base URL.

Synopsis

Defined in header <boost/url/url_base.hpp>

system::result< void >
resolve(
    url_view_base const& base,
    url_view_base const& ref,
    url_base& dest);
Description

This function attempts to resolve a URL reference ref against the base URL base in a manner similar to that of a web browser resolving an anchor tag. The base URL must satisfy the URI grammar. In other words, it must contain a scheme. Relative references are only usable when in the context of a base absolute URI. This process of resolving a relative reference within the context of a base URI is defined in detail in rfc3986 (see below). The resolution process works as if the relative reference is appended to the base URI and the result is normalized. Given the input base URL, this function resolves the relative reference as if performing the following steps:

This function places the result of the resolution into dest, which can be any of the url containers that inherit from url_base. If an error occurs, the contents of dest is unspecified and ec is set.

Remarks

Abnormal hrefs where the number of ".." segments exceeds the number of segments in the base path are handled by including the unmatched ".." segments in the result, as described in Errata 4547.

Example
url dest;
system::error_code ec;

resolve( "/one/two/three" , "four" , dest, ec);
assert( dest.str() == "/one/two/four" );

resolve( "http://example.com/" , "/one" , dest, ec);
assert( dest.str() == "http://example.com/one" );

resolve( "http://example.com/one" , "/two" , dest, ec);
assert( dest.str() == "http://example.com/two" );

resolve( "http://a/b/c/d;p?q" , "g#s" , dest, ec);
assert( dest.str() == "http://a/b/c/g#s" );
BNF
absolute-URI  = scheme ":" hier-part [ "?" query ]
Exception Safety

Basic guarantee. Calls to allocate may throw.

Return Value

An empty result upon success, otherwise an error code if !base.has_scheme().

Parameters

Name

Description

base

The base URL to resolve against.

ref

The URL reference to resolve.

dest

The container where the result is written, upon success.

Specification

5. Reference Resolution (rfc3986)

See Also

url, url_view.

Convenience header <boost/url.hpp>


PrevUpHomeNext