mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::URI Class Reference

Represents a Uniform Resource Identifier (URI) reference. More...

#include <uri.h>

Public Types

typedef std::string string_type
 The URI string_type.
 
typedef
std::experimental::string_view 
string_view
 The URI string_view.
 
typedef string_view::const_iterator const_iterator
 The URI const_iterator type.
 

Public Member Functions

 URI ()
 Default constructor. More...
 
 URI (const string_type &uri_str)
 Constructs a URI by parsing the given string. More...
 
 URI (string_type &&uri_str)
 Constructs a URI by parsing the given string. More...
 
 URI (string_view uri_str)
 Constructs a URI by parsing the given string. More...
 
 URI (const char *uri_str)
 Constructs a URI by parsing the given string. More...
 
template<class InputIter >
 URI (InputIter first, InputIter last)
 Constructs a URI by parsing the given string. More...
 
 URI (string_view scheme, string_view userInfo, string_view host, uint16_t port, string_view path, string_view query, string_view fragment)
 Constructs a hierarchical URI from the given components. More...
 
 URI (string_view scheme, string_view host, uint16_t port, string_view path, string_view query)
 Constructs a hierarchical URI from the given components. More...
 
 URI (const URI &other)
 Copy constructor. More...
 
 URI (URI &&other) noexcept
 Move constructor. More...
 
 ~URI () noexcept
 Destructor.
 
URIoperator= (const URI &other)
 Copy assignment operator. More...
 
URIoperator= (URI &&other)
 Move assignment operator. More...
 
URIoperator= (const string_type &uri_str)
 String assignment operator. More...
 
URIoperator= (string_type &&uri_str)
 Move string assignment operator. More...
 
URIoperator= (string_view uri_str)
 String view assignment operator. More...
 
URIoperator= (const char *uri_str)
 C-string assignment operator. More...
 
void swap (URI &other) noexcept
 Swaps one uri object with another. More...
 
const_iterator begin () const noexcept
 Returns an iterator at the first element in the underlying URI view. More...
 
const_iterator end () const noexcept
 Returns an iterator at the last+1 element in the underlying URI view. More...
 
string_view scheme () const noexcept
 Returns the scheme component of this URI. More...
 
void set_scheme (string_view scheme)
 Sets scheme component to this URI. More...
 
string_view user_info () const noexcept
 Returns the userInfo component of this URI. More...
 
void set_user_info (string_view user_info)
 Sets user_info component to this URI. More...
 
string_view host () const noexcept
 Returns the host component of this URI. More...
 
void set_host (string_view host)
 Sets host component to this URI. More...
 
string_view port_view () const noexcept
 Returns the port view component of this URI. More...
 
uint16_t port () const noexcept
 Returns the port component of this URI. More...
 
void set_port (string_view port)
 Sets port component to this URI. More...
 
void set_port (uint16_t port)
 Sets port component to this URI. More...
 
string_view path () const noexcept
 Returns the path view component of this URI. More...
 
void set_path (string_view path)
 Sets path component to this URI. More...
 
string_view query () const noexcept
 Returns the query view component of this URI. More...
 
void set_query (string_view query)
 Sets query component to this URI. More...
 
void add_to_query (string_view name, string_view value)
 Adds name-value pair to the current query component of this URI. More...
 
void parse_query (std::function< void(std::string &&, std::string &&)> consumer)
 Parses this URI's query into name-value pairs and feeds them to a given consumer. More...
 
string_view fragment () const noexcept
 Returns the fragment view component of this URI. More...
 
void set_fragment (string_view fragment)
 Sets fragment component to this URI. More...
 
bool has_authority () const noexcept
 Tests whether this URI has a valid authority. More...
 
string_view authority () const noexcept
 Returns the raw authority component of this URI. More...
 
string_view uri_view () const noexcept
 Returns the string view representation of this URI. More...
 
const std::string & string () const noexcept
 Returns the URI as a std::string object. More...
 
std::string && string_move ()
 Returns the URI as a std::string&& object. More...
 
std::string to_ASCII_string () const
 Returns the content of this URI as a US-ASCII string. More...
 
bool empty () const noexcept
 Tells whether or not this URI is empty. More...
 
bool is_absolute () const noexcept
 Tells whether or not this URI is absolute. More...
 
bool is_opaque () const noexcept
 Tells whether or not this URI is opaque. More...
 
void normalize_path ()
 Normalizes this URI's path. More...
 
void normalize ()
 Normalizes this URI. More...
 
URI create_normalized () const
 Create normalized copy of this URI. More...
 
URI create_with_normalized_path () const
 Create copy of this URI with normalized path. More...
 
URI relativize (const URI &uri) const
 Relativizes the given URI against this URI. More...
 
URI resolve (const URI &uri) const
 Resolves the given URI against this URI. More...
 
int compare (const URI &other) const noexcept
 Compares this URI against another. More...
 

Static Public Member Functions

static void parse_query (string_view query, std::function< void(std::string &&, std::string &&)> consumer)
 Parses a given query string into name-value pairs and feeds them to a given consumer. More...
 
static uint16_t get_default_port (string_view scheme)
 Returns default port for given scheme or 0 if the default port could not be found. More...
 
static std::string decode (string_view str)
 Decode all the persent encoded characters in the string. More...
 

Detailed Description

Represents a Uniform Resource Identifier (URI) reference.

This class conforms to a URI as defined by RFC 3986, RFC 3987 and RFC 2732, including scoped IDs. It provides member functions for normalizing, comparing and resolving URIs.

This class provides constructors for creating URI instances from their components or by parsing their string forms, methods for accessing the various components of an instance, and methods for normalizing, resolving, and relativizing URI instances. Instances of this class are mutable.

URI syntax and components

At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax

[scheme:]scheme-specific-part[#fragment]

where square brackets [...] delineate optional components and the characters : and # stand for themselves.

An absolute URI specifies a scheme; a URI that is not absolute is said to be relative. URIs are also classified according to whether they are opaque or hierarchical.

An opaque URI is an absolute URI whose scheme-specific part does not begin with a slash character ('/'). Opaque URIs are not subject to further parsing. Some examples of opaque URIs are:

java-.nosp@m.net@.nosp@m.java..nosp@m.sun..nosp@m.com
news:comp.lang.java

A hierarchical URI is either an absolute URI whose scheme-specific part begins with a slash character, or a relative URI, that is, a URI that does not specify a scheme. Some examples of hierarchical URIs are:

http://java.sun.com/j2se/1.3/
docs/guide/collections/designfaq.html#28
../../../demo/jfc/SwingSet2/src/SwingSet2.java
file:///~/calendar

A hierarchical URI is subject to further parsing according to the syntax

[scheme:][//authority][path][?query][#fragment]

where the characters :, /, ?, and # stand for themselves. The scheme-specific part of a hierarchical URI consists of the characters between the scheme and fragment components.

The authority component of a hierarchical URI is, if specified, either server-based or registry-based. A server-based authority parses according to the familiar syntax

[user-info@]host[:port]

where the characters @ and : stand for themselves. Nearly all URI schemes currently in use are server-based. An authority component that does not parse in this way is considered to be registry-based.

The path component of a hierarchical URI is itself said to be absolute if it begins with a slash character ('/'); otherwise it is relative. The path of a hierarchical URI that is either absolute or specifies an authority is always absolute.

All told, then, a URI instance has the following nine components:

ComponentType
schemestring_view
scheme-specific-part    string_view
authoritystring_view
user-infostring_view
hoststring_view
portuint16_t
pathstring_view
querystring_view
fragmentstring_view

In a given instance any particular component is either undefined or defined with a distinct value. Undefined string components are represented by empty view, while undefined integer components are represented by 0.

Whether a particular component is or is not defined in an instance depends upon the type of the URI being represented. An absolute URI has a scheme component. An opaque URI has a scheme, a scheme-specific part, and possibly a fragment, but has no other components. A hierarchical URI always has a path (though it may be empty) and a scheme-specific-part (which at least contains the path), and may have any of the other components. If the authority component is present and is server-based then the host component will be defined and the user-information and port components may be defined.

Operations on URI instances

The key operations supported by this class are those of normalization, resolution, and relativization.

Normalization is the process of removing unnecessary "." and ".." segments from the path component of a hierarchical URI. Each "." segment is simply removed. A ".." segment is removed only if it is preceded by a non-".." segment. Normalization has no effect upon opaque URIs.

Resolution is the process of resolving one URI against another, base URI. The resulting URI is constructed from components of both URIs in the manner specified by RFC 2396, taking components from the base URI for those not specified in the original. For hierarchical URIs, the path of the original is resolved against the path of the base and then normalized. The result, for example, of resolving

docs/guide/collections/designfaq.html#28          (1)

against the base URI http://java.sun.com/j2se/1.3/ is the result URI

http://java.sun.com/j2se/1.3/docs/guide/collections/designfaq.html#28

Resolving the relative URI

../../../demo/jfc/SwingSet2/src/SwingSet2.java    (2)

against this result yields, in turn,

http://java.sun.com/j2se/1.3/demo/jfc/SwingSet2/src/SwingSet2.java

Resolution of both absolute and relative URIs, and of both absolute and relative paths in the case of hierarchical URIs, is supported. Resolving the URI file:///~calendar against any other URI simply yields the original URI, since it is absolute. Resolving the relative URI (2) above against the relative base URI (1) yields the normalized, but still relative, URI

demo/jfc/SwingSet2/src/SwingSet2.java

Relativization, finally, is the inverse of resolution: For any two normalized URIs u and v,

u.relativize(u.resolve(v)) == v  and
u.resolve(u.relativize(v)) == v  .

This operation is often useful when constructing a document containing URIs that must be made relative to the base URI of the document wherever possible. For example, relativizing the URI

http://java.sun.com/j2se/1.3/docs/guide/index.html

against the base URI

http://java.sun.com/j2se/1.3

yields the relative URI docs/guide/index.html.

URIs, URLs, and URNs

A URI is a uniform resource identifier while a URL is a uniform resource locator. Hence every URL is a URI, abstractly speaking, but not every URI is a URL. This is because there is another subcategory of URIs, uniform resource names (URNs), which name resources but do not specify how to locate them. The mailto, news, and isbn URIs shown above are examples of URNs.

An instance of this class represents a URI reference in the syntactic sense defined by RFC 2396. A URI may be either absolute or relative. A URI string is parsed according to the generic syntax without regard to the scheme, if any, that it specifies. No lookup of the host, if any, is performed, and no scheme-dependent stream handler is constructed. Equality, hashing, and comparison are defined strictly in terms of the character content of the instance. In other words, a URI instance is little more than a structured string that supports the syntactic, scheme-independent operations of comparison, normalization, resolution, and relativization.

See Also
RFC 2279: UTF-8, a transformation format of ISO 10646,
RFC 2373: IPv6 Addressing Architecture,
RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,
RFC 2732: Format for Literal IPv6 Addresses in URLs

Constructor & Destructor Documentation

servlet::URI::URI ( )
inline

Default constructor.

Creates empty URI.

servlet::URI::URI ( const string_type uri_str)
inlineexplicit

Constructs a URI by parsing the given string.

This constructor parses the given string as specified by the grammar in RFC 2396, Appendix A, except for the following deviations:

  • An empty authority component is permitted as long as it is followed by a non-empty path, a query component, or a fragment component. This allows the parsing of URIs such as "file:///foo/bar", which seems to be the intent of RFC 2396 although the grammar does not permit it. If the authority component is empty then the user-information, host, and port components are undefined.

  • Empty relative paths are permitted; this seems to be the intent of RFC 2396 although the grammar does not permit it. The primary consequence of this deviation is that a standalone fragment such as "#foo" parses as a relative URI with an empty path and the given fragment, and can be usefully resolved against a base URI.

  • IPv4 addresses are not validated.

  • IPv6 addresses are permitted for the host component. An IPv6 address must be enclosed in square brackets ('[' and ']') as specified by RFC 2732. Other than this constraint IPv6 addresses are not validated.

  • Characters in the other category are permitted wherever RFC 2396 permits escaped octets, that is, in the user-information, path, query, and fragment components, as well as in the authority component if the authority is registry-based. This allows URIs to contain Unicode characters beyond those in the US-ASCII character set.

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
servlet::URI::URI ( string_type &&  uri_str)
inlineexplicit

Constructs a URI by parsing the given string.

URI string is parsed as described in URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
servlet::URI::URI ( string_view  uri_str)
inlineexplicit

Constructs a URI by parsing the given string.

URI string is parsed as described in URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
servlet::URI::URI ( const char *  uri_str)
inlineexplicit

Constructs a URI by parsing the given string.

URI string is parsed as described in URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
template<class InputIter >
servlet::URI::URI ( InputIter  first,
InputIter  last 
)
inline

Constructs a URI by parsing the given string.

URI string is constructed from first, last iterators and the string is parsed further as described in URI(const string_type&)

Template Parameters
InputIterinput iterator type from which URI string will be created
Parameters
firstBegin iterator to URI string
lastEnd iterator to URI string
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
servlet::URI::URI ( string_view  scheme,
string_view  userInfo,
string_view  host,
uint16_t  port,
string_view  path,
string_view  query,
string_view  fragment 
)

Constructs a hierarchical URI from the given components.

If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). If the path begins not with slash, than slash will be prepended to it to facilitate relative paths. Otherwise initial component of the new URI may be left undefined by passing empty view for the corresponding parameter or, in the case of the port parameter, by passing 0 or negative value.

This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section 5.2, step 7:

  1. Initially, the result string is empty.

  2. If a scheme is given then it is appended to the result, followed by a colon character (':').

  3. If user information, a host, or a port are given then the string "//" is appended.

  4. If user information is given then it is appended, followed by a commercial-at character ('@').

  5. If a host is given then it is appended.

  6. If a port number is given then a colon character (':') is appended, followed by the port number in decimal.

  7. If a path is given then it is appended.

  8. If a query is given then a question-mark character ('?') is appended, followed by the query.

  9. Finally, if a fragment is given then a hash character ('#') is appended, followed by the fragment.

No further parsing for the resulting URI string is attempted.

Parameters
schemeScheme name
userInfoUser name and authorization information
hostHost name
portPort number
pathPath
queryQuery
fragmentFragment
servlet::URI::URI ( string_view  scheme,
string_view  host,
uint16_t  port,
string_view  path,
string_view  query 
)
inline

Constructs a hierarchical URI from the given components.

This constructor follows the same rules as URI(string_view scheme, string_view userInfo, string_view host, uint16_t port, string_view path, string_view query, string_view fragment) but with empty userInfo and fragment.

Parameters
schemeScheme name
hostHost name
portPort number
pathPath
queryQuery
See Also
URI(string_view scheme, string_view userInfo, string_view host, uint16_t port, string_view path, string_view query, string_view fragment)
servlet::URI::URI ( const URI other)
inline

Copy constructor.

Parameters
otherURI to copy from
servlet::URI::URI ( URI &&  other)
inlinenoexcept

Move constructor.

Parameters
otherURI to move from

Member Function Documentation

void servlet::URI::add_to_query ( string_view  name,
string_view  value 
)

Adds name-value pair to the current query component of this URI.

If query component already exists, this method will append "&name=value" string, otherwise new query component will be created as "name=value"

No parsing or validation is performed in this method.

Parameters
nameName of new name-value pair of query component of this URI
valueValue of new name-value pair of query component of this URI
string_view servlet::URI::authority ( ) const
noexcept

Returns the raw authority component of this URI.

The authority component of a URI, if defined, only contains the commercial-at character ('@') and characters in the unreserved, punct, escaped, and other categories. If the authority is server-based then it is further constrained to have valid user-information, host, and port components.

Returns
The raw authority component of this URI, or null if the authority is undefined
const_iterator servlet::URI::begin ( ) const
inlinenoexcept

Returns an iterator at the first element in the underlying URI view.

Returns
A begin iterator of underlying string view of the URI.
int servlet::URI::compare ( const URI other) const
noexcept

Compares this URI against another.

Before comparing the URIs are normalized. If this is not a desired behaviour comparison operators should be used to compare URIs without normalization.

Parameters
otherThe URI to compare to this.
Returns
0 if the URIs are considered equal, negative value if this is less than other and and positive value if this is greater than other.
See Also
operator==(const URI&, const URI&)
operator!=(const URI&, const URI&)
operator<(const URI&, const URI&)
operator>(const URI&, const URI&)
operator<=(const URI&, const URI&)
operator>=(const URI&, const URI&)
URI servlet::URI::create_normalized ( ) const

Create normalized copy of this URI.

Copy of this URI is created and normalize method is called on the copy

Returns
Normalized URI instance
See Also
normalize
URI servlet::URI::create_with_normalized_path ( ) const

Create copy of this URI with normalized path.

Copy of this URI is created and normalize_path method is called on the copy

Returns
Normalized URI instance
See Also
normalize_path
static std::string servlet::URI::decode ( string_view  str)
static

Decode all the persent encoded characters in the string.

Parameters
strStrign view to decode.
Returns
Decoded string.
bool servlet::URI::empty ( ) const
inlinenoexcept

Tells whether or not this URI is empty.

A URI is absolute if, and only if, it has no components.

Returns
true if, and only if, this URI has no components defined
const_iterator servlet::URI::end ( ) const
inlinenoexcept

Returns an iterator at the last+1 element in the underlying URI view.

Returns
A end iterator of underlying string view of the URI.
string_view servlet::URI::fragment ( ) const
inlinenoexcept

Returns the fragment view component of this URI.

Returns
The fragment view component of this URI, or empty view if the fragment is undefined
static uint16_t servlet::URI::get_default_port ( string_view  scheme)
static

Returns default port for given scheme or 0 if the default port could not be found.

Parameters
schemeThe scheme for which to find the default port
Returns
default port for a given scheme or 0 if the default port is not found.
bool servlet::URI::has_authority ( ) const
noexcept

Tests whether this URI has a valid authority.

Returns
true if the URI has an authority, false otherwise.
string_view servlet::URI::host ( ) const
inlinenoexcept

Returns the host component of this URI.

Returns
The host component of this URI, or empty view if the host is undefined
bool servlet::URI::is_absolute ( ) const
inlinenoexcept

Tells whether or not this URI is absolute.

A URI is absolute if, and only if, it has a scheme component.

Returns
true if, and only if, this URI is absolute
bool servlet::URI::is_opaque ( ) const
noexcept

Tells whether or not this URI is opaque.

A URI is opaque if, and only if, it is absolute and its scheme-specific part does not begin with a slash character ('/'). An opaque URI has a scheme, a scheme-specific part, and possibly a fragment; all other components are undefined.

Returns
true if, and only if, this URI is opaque
void servlet::URI::normalize ( )

Normalizes this URI.

The normalization includes:

  1. All alphabetic characters in the scheme component are converted to lower-case

  2. All persent encoded characters are decoded

  3. Path component is normalized as described in normalize_path

See Also
normalize_path
void servlet::URI::normalize_path ( )

Normalizes this URI's path.

The path is normalized in a manner consistent with RFC 2396, section 5.2, step 6, sub-steps c through f; that is:

  1. All "." segments are removed.

  2. If a ".." segment is preceded by a non-".." segment then both of these segments are removed. This step is repeated until it is no longer applicable.

A normalized path will begin with one or more ".." segments if there were insufficient non-".." segments preceding them to allow their removal. Otherwise, a normalized path will not contain any "." or ".." segments.

URI& servlet::URI::operator= ( const URI other)

Copy assignment operator.

Parameters
otherURI to copy from
URI& servlet::URI::operator= ( URI &&  other)

Move assignment operator.

Parameters
otherURI to move from
URI& servlet::URI::operator= ( const string_type uri_str)
inline

String assignment operator.

Assigns the string representation of URI to this URI object. The string is parsed following the rules to string constructor URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
URI& servlet::URI::operator= ( string_type &&  uri_str)
inline

Move string assignment operator.

Assigns the string representation of URI to this URI object. The string is parsed following the rules to string constructor URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
URI& servlet::URI::operator= ( string_view  uri_str)
inline

String view assignment operator.

Assigns the string representation of URI to this URI object. The string is parsed following the rules to string constructor URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
URI& servlet::URI::operator= ( const char *  uri_str)
inline

C-string assignment operator.

Assigns the string representation of URI to this URI object. The string is parsed following the rules to string constructor URI(const string_type&)

Parameters
uri_strThe string to be parsed into a URI
Exceptions
uri_syntax_errorIf the given string violates RFC 2396, as augmented by the above deviations
See Also
URI(const string_type&)
void servlet::URI::parse_query ( std::function< void(std::string &&, std::string &&)>  consumer)
inline

Parses this URI's query into name-value pairs and feeds them to a given consumer.

This function is equivalent of calling:

URI::parse_uri(query(), consumer);
Parameters
consumerstd::function to feed name-value pairs to.
See Also
parse_query(string_view , std::function<void(const std::string&, const std::string&)>)
static void servlet::URI::parse_query ( string_view  query,
std::function< void(std::string &&, std::string &&)>  consumer 
)
static

Parses a given query string into name-value pairs and feeds them to a given consumer.

Before adding the name-value pairs to the consumer the are decodes from all the persent encoded characters.

The consumer here is used for genericity not to restrict type of map object passed to the method. For example:

custom_map name_value_map;
URI::parse_query(query, [&name_value_map] (const std::string& name, const std::string& value)
{
name_value_map.emplace(std::move(name), std::move(value));
});
Parameters
queryquery string view
consumerstd::function to feed name-value pairs to.
See Also
parse_query(std::function<void(const std::string&, const std::string&)>)
string_view servlet::URI::path ( ) const
inlinenoexcept

Returns the path view component of this URI.

Returns
The path view component of this URI, or empty view if the path is undefined
uint16_t servlet::URI::port ( ) const
inlinenoexcept

Returns the port component of this URI.

Returns
The port component of this URI, or 0 if the port is undefined
string_view servlet::URI::port_view ( ) const
inlinenoexcept

Returns the port view component of this URI.

Returns
The port view component of this URI, or empty view if the port is undefined
string_view servlet::URI::query ( ) const
inlinenoexcept

Returns the query view component of this URI.

Returns
The query view component of this URI, or empty view if the query is undefined
URI servlet::URI::relativize ( const URI uri) const

Relativizes the given URI against this URI.

The relativization of the given URI against this URI is computed as follows:

  1. If either this URI or the given URI are opaque, or if the scheme and authority components of the two URIs are not identical, or if the path of this URI is not a prefix of the path of the given URI, then the given URI is returned.

  2. Otherwise a new relative hierarchical URI is constructed with query and fragment components taken from the given URI and with a path component computed by removing this URI's path from the beginning of the given URI's path.

Parameters
uriThe URI to be relativized against this URI
Returns
The resulting URI
URI servlet::URI::resolve ( const URI uri) const

Resolves the given URI against this URI.

If the given URI is already absolute, or if this URI is opaque, then the given URI is returned.

<If the given URI's fragment component is defined, its path component is empty, and its scheme, authority, and query components are undefined, then a URI with the given fragment but with all other components equal to those of this URI is returned. This allows a URI representing a standalone fragment reference, such as "#foo", to be usefully resolved against a base URI.

Otherwise this method constructs a new hierarchical URI in a manner consistent with RFC 2396, section 5.2; that is:

  1. A new URI is constructed with this URI's scheme and the given URI's query and fragment components.

  2. If the given URI has an authority component then the new URI's authority and path are taken from the given URI.

  3. Otherwise the new URI's authority component is copied from this URI, and its path is computed as follows:

    1. If the given URI's path is absolute then the new URI's path is taken from the given URI.

    2. Otherwise the given URI's path is relative, and so the new URI's path is computed by resolving the path of the given URI against the path of this URI. This is done by concatenating all but the last segment of this URI's path, if any, with the given URI's path and then normalizing the result as if by invoking the normalize method.

The result of this method is absolute if, and only if, either this URI is absolute or the given URI is absolute.

Parameters
uriThe URI to be resolved against this URI
Returns
The resulting URI
string_view servlet::URI::scheme ( ) const
inlinenoexcept

Returns the scheme component of this URI.

Returns
The scheme component of this URI, or empty view if the scheme is undefined
void servlet::URI::set_fragment ( string_view  fragment)

Sets fragment component to this URI.

New fragment component replaces the old one. If new fragment component is empty, the current fragment component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
fragmentNew fragment component to this URI
void servlet::URI::set_host ( string_view  host)

Sets host component to this URI.

New host component replaces the old one. If new host component is empty, the current host component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
hostNew host component to this URI
void servlet::URI::set_path ( string_view  path)

Sets path component to this URI.

New path component replaces the old one. If new path component is empty, the current path component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
pathNew path component to this URI
Exceptions
uri_syntax_errorIf the given path component is not empty and does not begin with slash character "/"
void servlet::URI::set_port ( string_view  port)

Sets port component to this URI.

New port component replaces the old one. If new port component is empty, the current port component will be deleted and considered to be undefined

This method validates port, by reading uint16_t representation. No forther parsing is performed in this method.

Parameters
portNew port component to this URI
void servlet::URI::set_port ( uint16_t  port)

Sets port component to this URI.

New port component replaces the old one. If new port component is 0 or negative, the current port component will be deleted and considered to be undefined

No forther parsing is performed in this method.

Parameters
portNew port component to this URI
void servlet::URI::set_query ( string_view  query)

Sets query component to this URI.

New query component replaces the old one. If new query component is empty, the current path component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
queryNew query component to this URI
void servlet::URI::set_scheme ( string_view  scheme)

Sets scheme component to this URI.

New scheme component replaces the old one. If new scheme component is empty, the current scheme component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
schemeNew scheme component to this URI
void servlet::URI::set_user_info ( string_view  user_info)

Sets user_info component to this URI.

New user_info component replaces the old one. If new user_info component is empty, the current user_info component will be deleted and considered to be undefined

No parsing or validation is performed in this method.

Parameters
user_infoNew user_info component to this URI
const std::string& servlet::URI::string ( ) const
inlinenoexcept

Returns the URI as a std::string object.

Returns
A URI string.
std::string&& servlet::URI::string_move ( )
inline

Returns the URI as a std::string&& object.

This method can be used to move the string representation out of this URI if this object is not intended to be used further

Returns
A moved URI string.
void servlet::URI::swap ( URI other)
noexcept

Swaps one uri object with another.

Parameters
otherThe other uri object.
std::string servlet::URI::to_ASCII_string ( ) const

Returns the content of this URI as a US-ASCII string.

If this URI does not contain any characters in the other category then an invocation of this method will return the same value as an invocation of the string method. Otherwise this method works as if by invoking that method and then encoding the result.

Returns
The string form of this URI, encoded as needed so that it only contains characters in the US-ASCII charset
string_view servlet::URI::uri_view ( ) const
inlinenoexcept

Returns the string view representation of this URI.

Returns
The string view representation of this URI, or empty view if the URI doesn't have any components undefined
string_view servlet::URI::user_info ( ) const
inlinenoexcept

Returns the userInfo component of this URI.

Returns
The userInfo component of this URI, or empty view if the userInfo is undefined

The documentation for this class was generated from the following file: