[Generic Function] merge-uris

Signature

merge-uris uri base &optional place => result-uri

Package

ystok.uri

Arguments
uri
An instance of the uri structure class, string, or another object representing a relative or absolute URI.
base
An instance of the uri structure class, string, or another object representing an absolute URI.
place
If given, must be a uri instance that will used as a storage for the result rather than a new one being created.
Values

A newly created uri instance or the place if given.

Description

The function converts the uri reference that might be relative to the given base URI. The result-uri contains the same parsed components as the reference's target.

The simplified procedure of merging is as follows.

  1. If uri has a scheme,
    then the copy of uri is returned (strict parser),
    else the result-uri inherits the scheme from base.
  2. If uri has an authority,
    then the copy of uri is returned with the scheme inherited,
    else the result-uri inherits the authority from base.
  3. If uri path is empty (i.e. null), then
    - the query of either uri or base (if the former is null) is used,
    - the fragment of uri is used,
    - all other slots are inherited from base.
  4. If the path of uri is absolute (starts with a '/'),
    then this path along with query and fragment of uri are used in result-uri.
  5. Otherwise,
    - the paths of base and uri are merged into a result-uri path,
    - the query and fragment of uri are used unmodified in result-uri.

The rules for merging URIs are not the same as for merging pathnames.