:relfileprefix: ../../../
[#boost-urls-url_base-08friend]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::resolve


Resolve a URL reference against a base URL


=== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_base.hpp#L2879[boost/url/url_base.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
friend
system::result<void>
resolve(
    xref:boost/urls/url_view_base.adoc[url_view_base] const& base,
    xref:boost/urls/url_view_base.adoc[url_view_base] const& ref,
    xref:boost/urls/url_base.adoc[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:

* Ensure the base URI has at least a scheme

* Normalizing the reference path

* Merge base and reference paths

* Normalize the merged path

This function places the result of the
resolution into `dest`, which can be
any of the url containers that inherit
from
xref:boost/urls/url_base.adoc[url_base]
.

If an error occurs, the contents of
`dest` is unspecified and `ec` is set.
[NOTE]

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
link:https://www.rfc-editor.org/errata/eid4547[Errata 4547]
.
[,cpp]
----
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" );
----
[,cpp]
----
absolute-URI  = scheme ":" hier-part [ "?" query ]
----

=== Basic guarantee.

Calls to allocate may throw.

=== 5. Reference Resolution (rfc3986)



=== See Also


xref:boost/urls/url.adoc[url]
,
xref:boost/urls/url_view.adoc[url_view]
.



