Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::URI Class Reference

#include <URI.h>

Public Types

using QueryParameters = std::vector<std::pair<std::string, std::string>>
 

Public Member Functions

 URI ()
 
 URI (const std::string &uri)
 Creates an empty URI.
 
 URI (const char *uri)
 
 URI (const std::string &scheme, const std::string &pathEtc)
 
 URI (const std::string &scheme, const std::string &authority, const std::string &pathEtc)
 Creates an URI from its parts.
 
 URI (const std::string &scheme, const std::string &authority, const std::string &path, const std::string &query)
 Creates an URI from its parts.
 
 URI (const std::string &scheme, const std::string &authority, const std::string &path, const std::string &query, const std::string &fragment)
 Creates an URI from its parts.
 
 URI (const URI &uri)
 Creates an URI from its parts.
 
 URI (URI &&uri) noexcept
 Copy constructor. Creates an URI from another one.
 
 URI (const URI &baseURI, const std::string &relativeURI)
 Move constructor.
 
 URI (const Path &path)
 
 ~URI ()
 
URIoperator= (const URI &uri)
 Destroys the URI.
 
URIoperator= (URI &&uri) noexcept
 Assignment operator.
 
URIoperator= (const std::string &uri)
 Move assignment.
 
URIoperator= (const char *uri)
 
void swap (URI &uri)
 
void clear ()
 Swaps the URI with another one.
 
std::string toString () const
 Clears all parts of the URI.
 
const std::string & getScheme () const
 
void setScheme (const std::string &scheme)
 Returns the scheme part of the URI.
 
const std::string & getUserInfo () const
 
void setUserInfo (const std::string &userInfo)
 Returns the user-info part of the URI.
 
const std::string & getHost () const
 Sets the user-info part of the URI.
 
void setHost (const std::string &host)
 Returns the host part of the URI.
 
unsigned short getPort () const
 Sets the host part of the URI.
 
void setPort (unsigned short port)
 
unsigned short getSpecifiedPort () const
 Sets the port number part of the URI.
 
std::string getAuthority () const
 
void setAuthority (const std::string &authority)
 
const std::string & getPath () const
 
void setPath (const std::string &path)
 Returns the decoded path part of the URI.
 
std::string getQuery () const
 Sets the path part of the URI.
 
void setQuery (const std::string &query)
 
void addQueryParameter (const std::string &param, const std::string &val="")
 
const std::string & getRawQuery () const
 
void setRawQuery (const std::string &query)
 
QueryParameters getQueryParameters () const
 
void setQueryParameters (const QueryParameters &params)
 
const std::string & getFragment () const
 
void setFragment (const std::string &fragment)
 Returns the fragment part of the URI.
 
void setPathEtc (const std::string &pathEtc)
 Sets the fragment part of the URI.
 
std::string getPathEtc () const
 Sets the path, query and fragment parts of the URI.
 
std::string getPathAndQuery () const
 Returns the encoded path, query and fragment parts of the URI.
 
void resolve (const std::string &relativeURI)
 Returns the encoded path and query parts of the URI.
 
void resolve (const URI &relativeURI)
 
bool isRelative () const
 
bool empty () const
 
bool operator== (const URI &uri) const
 Returns true if the URI is empty, false otherwise.
 
bool operator== (const std::string &uri) const
 
bool operator!= (const URI &uri) const
 
bool operator!= (const std::string &uri) const
 Returns true if both URIs are identical, false otherwise.
 
void normalize ()
 
void getPathSegments (std::vector< std::string > &segments) const
 

Static Public Member Functions

static void encode (const std::string &str, const std::string &reserved, std::string &encodedStr)
 
static void decode (const std::string &str, std::string &decodedStr, bool plusAsSpace=false)
 

Protected Member Functions

bool equals (const URI &uri) const
 
bool isWellKnownPort () const
 Returns true if both uri's are equivalent.
 
unsigned short getWellKnownPort () const
 
void parse (const std::string &uri)
 
void parseAuthority (std::string::const_iterator &it, const std::string::const_iterator &end)
 
void parseHostAndPort (std::string::const_iterator &it, const std::string::const_iterator &end)
 Parses and sets the user-info, host and port from the given data.
 
void parsePath (std::string::const_iterator &it, const std::string::const_iterator &end)
 Parses and sets the host and port from the given data.
 
void parsePathEtc (std::string::const_iterator &it, const std::string::const_iterator &end)
 Parses and sets the path from the given data.
 
void parseQuery (std::string::const_iterator &it, const std::string::const_iterator &end)
 Parses and sets the path, query and fragment from the given data.
 
void parseFragment (std::string::const_iterator &it, const std::string::const_iterator &end)
 Parses and sets the query from the given data.
 
void mergePath (const std::string &path)
 Parses and sets the fragment from the given data.
 
void removeDotSegments (bool removeLeading=true)
 Appends a path to the URI's path.
 
void buildPath (const std::vector< std::string > &segments, bool leadingSlash, bool trailingSlash)
 

Static Protected Member Functions

static void getPathSegments (const std::string &path, std::vector< std::string > &segments)
 Removes all dot segments from the path.
 

Static Protected Attributes

static const std::string RESERVED_PATH
 Builds the path from the given segments.
 
static const std::string RESERVED_QUERY
 
static const std::string RESERVED_QUERY_PARAM
 
static const std::string RESERVED_FRAGMENT
 
static const std::string ILLEGAL
 

Private Attributes

std::string _scheme
 
std::string _userInfo
 
std::string _host
 
unsigned short _port
 
std::string _path
 
std::string _query
 
std::string _fragment
 

Detailed Description

A Uniform Resource Identifier, as specified in RFC 3986.

The URI class provides methods for building URIs from their
parts, as well as for splitting URIs into their parts.
Furthermore, the class provides methods for resolving
relative URIs against base URIs.

The class automatically performs a few normalizations on
all URIs and URI parts passed to it:
  * scheme identifiers are converted to lower case
  * percent-encoded characters are decoded (except for the query string)
  * optionally, dot segments are removed from paths (see normalize())

Note that dealing with query strings requires some precautions, as, internally,
query strings are stored in percent-encoded form, while all other parts of the URI
are stored in decoded form. While parsing query strings from properly encoded URLs
generally works, explicitly setting query strings with setQuery() or extracting
query strings with getQuery() may lead to ambiguities. See the descriptions of
setQuery(), setRawQuery(), getQuery() and getRawQuery() for more information. 

Definition at line 32 of file URI.h.

Member Typedef Documentation

◆ QueryParameters

using Poco::URI::QueryParameters = std::vector<std::pair<std::string, std::string>>

Definition at line 54 of file URI.h.

Constructor & Destructor Documentation

◆ URI() [1/11]

Poco::URI::URI ( )

◆ URI() [2/11]

Poco::URI::URI ( const std::string & uri)
explicit

Creates an empty URI.

+ Here is the caller graph for this function:

◆ URI() [3/11]

Poco::URI::URI ( const char * uri)
explicit

Parses an URI from the given string. Throws a SyntaxException if the uri is not valid.

◆ URI() [4/11]

Poco::URI::URI ( const std::string & scheme,
const std::string & pathEtc )

Parses an URI from the given string. Throws a SyntaxException if the uri is not valid.

◆ URI() [5/11]

Poco::URI::URI ( const std::string & scheme,
const std::string & authority,
const std::string & pathEtc )

Creates an URI from its parts.

◆ URI() [6/11]

Poco::URI::URI ( const std::string & scheme,
const std::string & authority,
const std::string & path,
const std::string & query )

Creates an URI from its parts.

◆ URI() [7/11]

Poco::URI::URI ( const std::string & scheme,
const std::string & authority,
const std::string & path,
const std::string & query,
const std::string & fragment )

Creates an URI from its parts.

◆ URI() [8/11]

Poco::URI::URI ( const URI & uri)

Creates an URI from its parts.

◆ URI() [9/11]

Poco::URI::URI ( URI && uri)
noexcept

Copy constructor. Creates an URI from another one.

◆ URI() [10/11]

Poco::URI::URI ( const URI & baseURI,
const std::string & relativeURI )

Move constructor.

◆ URI() [11/11]

Poco::URI::URI ( const Path & path)
explicit

Creates an URI from a base URI and a relative URI, according to the algorithm in section 5.2 of RFC 3986.

◆ ~URI()

Poco::URI::~URI ( )

Creates a URI from a path.

The path will be made absolute, and a file:// URI will be built from it.

Member Function Documentation

◆ addQueryParameter()

void Poco::URI::addQueryParameter ( const std::string & param,
const std::string & val = "" )

Sets the query part of the URI.

The query string will be percent-encoded. If the query already contains percent-encoded characters, these will be double-encoded, which is probably not what's intended by the caller. Furthermore, ampersand ('&') characters in the query will not be encoded. This could lead to ambiguity issues if the query string contains multiple name-value parameters separated by ampersand, and if any name or value also contains an ampersand. In such a case, it's better to use setRawQuery() with a properly percent-encoded query string, or use addQueryParameter() or setQueryParameters(), which take care of appropriate percent encoding of parameter names and values.

◆ buildPath()

void Poco::URI::buildPath ( const std::vector< std::string > & segments,
bool leadingSlash,
bool trailingSlash )
protected

Places the single path segments (delimited by slashes) into the given vector.

◆ clear()

void Poco::URI::clear ( )

Swaps the URI with another one.

◆ decode()

static void Poco::URI::decode ( const std::string & str,
std::string & decodedStr,
bool plusAsSpace = false )
static

URI-encodes the given string by escaping reserved and non-ASCII characters. The encoded string is appended to encodedStr.

◆ empty()

bool Poco::URI::empty ( ) const

Returns true if the URI is a relative reference, false otherwise.

A relative reference does not contain a scheme identifier. Relative references are usually resolved against an absolute base reference.

◆ encode()

static void Poco::URI::encode ( const std::string & str,
const std::string & reserved,
std::string & encodedStr )
static

Places the single path segments (delimited by slashes) into the given vector.

◆ equals()

bool Poco::URI::equals ( const URI & uri) const
protected

URI-decodes the given string by replacing percent-encoded characters with the actual character. The decoded string is appended to decodedStr.

When plusAsSpace is true, non-encoded plus signs in the query are decoded as spaces. (http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1)

◆ getAuthority()

std::string Poco::URI::getAuthority ( ) const

Returns the port number part of the URI.

If no explicit port number has been specified, returns 0.

◆ getFragment()

const std::string & Poco::URI::getFragment ( ) const
inline

Sets the query part of the URI from a vector of query parameters.

Calls addQueryParameter() for each parameter name and value.

Definition at line 403 of file URI.h.

◆ getHost()

const std::string & Poco::URI::getHost ( ) const
inline

Sets the user-info part of the URI.

Definition at line 385 of file URI.h.

+ Here is the caller graph for this function:

◆ getPath()

const std::string & Poco::URI::getPath ( ) const
inline

Parses the given authority part for the URI and sets the user-info, host, port components accordingly.

Definition at line 391 of file URI.h.

◆ getPathAndQuery()

std::string Poco::URI::getPathAndQuery ( ) const

Returns the encoded path, query and fragment parts of the URI.

+ Here is the caller graph for this function:

◆ getPathEtc()

std::string Poco::URI::getPathEtc ( ) const

Sets the path, query and fragment parts of the URI.

◆ getPathSegments() [1/2]

static void Poco::URI::getPathSegments ( const std::string & path,
std::vector< std::string > & segments )
staticprotected

Removes all dot segments from the path.

◆ getPathSegments() [2/2]

void Poco::URI::getPathSegments ( std::vector< std::string > & segments) const

Normalizes the URI by removing all but leading . and .. segments from the path.

If the first path segment in a relative path contains a colon (:), such as in a Windows path containing a drive letter, a dot segment (./) is prepended in accordance with section 3.3 of RFC 3986.

◆ getPort()

unsigned short Poco::URI::getPort ( ) const

Sets the host part of the URI.

+ Here is the caller graph for this function:

◆ getQuery()

std::string Poco::URI::getQuery ( ) const

Sets the path part of the URI.

◆ getQueryParameters()

QueryParameters Poco::URI::getQueryParameters ( ) const

Sets the query part of the URI.

The given query string must be properly percent-encoded.

◆ getRawQuery()

const std::string & Poco::URI::getRawQuery ( ) const
inline

Adds "param=val" to the query; "param" may not be empty. If val is empty, only '=' is appended to the parameter.

In addition to regular encoding, function also encodes '&' and '=', if found in param or val.

Definition at line 397 of file URI.h.

◆ getScheme()

const std::string & Poco::URI::getScheme ( ) const
inline

Returns a string representation of the URI.

Characters in the path, query and fragment parts will be percent-encoded as necessary.

Definition at line 373 of file URI.h.

+ Here is the caller graph for this function:

◆ getSpecifiedPort()

unsigned short Poco::URI::getSpecifiedPort ( ) const
inline

Sets the port number part of the URI.

Definition at line 409 of file URI.h.

◆ getUserInfo()

const std::string & Poco::URI::getUserInfo ( ) const
inline

Sets the scheme part of the URI. The given scheme is converted to lower-case.

A list of registered URI schemes can be found at http://www.iana.org/assignments/uri-schemes.

Definition at line 379 of file URI.h.

◆ getWellKnownPort()

unsigned short Poco::URI::getWellKnownPort ( ) const
protected

Returns true if the URI's port number is a well-known one (for example, 80, if the scheme is http).

◆ isRelative()

bool Poco::URI::isRelative ( ) const

Resolves the given relative URI against the base URI. See section 5.2 of RFC 3986 for the algorithm used.

◆ isWellKnownPort()

bool Poco::URI::isWellKnownPort ( ) const
protected

Returns true if both uri's are equivalent.

◆ mergePath()

void Poco::URI::mergePath ( const std::string & path)
protected

Parses and sets the fragment from the given data.

◆ normalize()

void Poco::URI::normalize ( )

Parses the given URI and returns true if both URIs are identical, false otherwise.

◆ operator!=() [1/2]

bool Poco::URI::operator!= ( const std::string & uri) const

Returns true if both URIs are identical, false otherwise.

◆ operator!=() [2/2]

bool Poco::URI::operator!= ( const URI & uri) const

Parses the given URI and returns true if both URIs are identical, false otherwise.

◆ operator=() [1/4]

URI & Poco::URI::operator= ( const char * uri)

Parses and assigns an URI from the given string. Throws a SyntaxException if the uri is not valid.

◆ operator=() [2/4]

URI & Poco::URI::operator= ( const std::string & uri)

Move assignment.

◆ operator=() [3/4]

URI & Poco::URI::operator= ( const URI & uri)

Destroys the URI.

◆ operator=() [4/4]

URI & Poco::URI::operator= ( URI && uri)
noexcept

Assignment operator.

◆ operator==() [1/2]

bool Poco::URI::operator== ( const std::string & uri) const

Returns true if both URIs are identical, false otherwise.

Two URIs are identical if their scheme, authority, path, query and fragment part are identical.

◆ operator==() [2/2]

bool Poco::URI::operator== ( const URI & uri) const

Returns true if the URI is empty, false otherwise.

◆ parse()

void Poco::URI::parse ( const std::string & uri)
protected

Returns the well-known port number for the URI's scheme, or 0 if the port number is not known.

◆ parseAuthority()

void Poco::URI::parseAuthority ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and assigns an URI from the given string. Throws a SyntaxException if the uri is not valid.

◆ parseFragment()

void Poco::URI::parseFragment ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and sets the query from the given data.

◆ parseHostAndPort()

void Poco::URI::parseHostAndPort ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and sets the user-info, host and port from the given data.

◆ parsePath()

void Poco::URI::parsePath ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and sets the host and port from the given data.

◆ parsePathEtc()

void Poco::URI::parsePathEtc ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and sets the path from the given data.

◆ parseQuery()

void Poco::URI::parseQuery ( std::string::const_iterator & it,
const std::string::const_iterator & end )
protected

Parses and sets the path, query and fragment from the given data.

◆ removeDotSegments()

void Poco::URI::removeDotSegments ( bool removeLeading = true)
protected

Appends a path to the URI's path.

◆ resolve() [1/2]

void Poco::URI::resolve ( const std::string & relativeURI)

Returns the encoded path and query parts of the URI.

◆ resolve() [2/2]

void Poco::URI::resolve ( const URI & relativeURI)

Resolves the given relative URI against the base URI. See section 5.2 of RFC 3986 for the algorithm used.

◆ setAuthority()

void Poco::URI::setAuthority ( const std::string & authority)

Returns the authority part (userInfo, host and port) of the URI.

If the port number is a well-known port number for the given scheme (e.g., 80 for http), it is not included in the authority.

◆ setFragment()

void Poco::URI::setFragment ( const std::string & fragment)

Returns the fragment part of the URI.

◆ setHost()

void Poco::URI::setHost ( const std::string & host)

Returns the host part of the URI.

◆ setPath()

void Poco::URI::setPath ( const std::string & path)

Returns the decoded path part of the URI.

◆ setPathEtc()

void Poco::URI::setPathEtc ( const std::string & pathEtc)

Sets the fragment part of the URI.

◆ setPort()

void Poco::URI::setPort ( unsigned short port)

Returns the port number part of the URI.

If no port number (0) has been specified, the well-known port number (e.g., 80 for http) for the given scheme is returned if it is known. Otherwise, 0 is returned.

◆ setQuery()

void Poco::URI::setQuery ( const std::string & query)

Returns the decoded query part of the URI.

Note that encoded ampersand characters ('&', "%26") will be decoded, which could cause ambiguities if the query string contains multiple parameters and a parameter name or value contains an ampersand as well. In such a case it's better to use getRawQuery() or getQueryParameters().

◆ setQueryParameters()

void Poco::URI::setQueryParameters ( const QueryParameters & params)

Returns the decoded query string parameters as a vector of name-value pairs.

◆ setRawQuery()

void Poco::URI::setRawQuery ( const std::string & query)

Returns the query string in raw form, which usually means percent encoded.

◆ setScheme()

void Poco::URI::setScheme ( const std::string & scheme)

Returns the scheme part of the URI.

◆ setUserInfo()

void Poco::URI::setUserInfo ( const std::string & userInfo)

Returns the user-info part of the URI.

◆ swap()

void Poco::URI::swap ( URI & uri)

Parses and assigns an URI from the given string. Throws a SyntaxException if the uri is not valid.

+ Here is the caller graph for this function:

◆ toString()

std::string Poco::URI::toString ( ) const

Clears all parts of the URI.

Member Data Documentation

◆ _fragment

std::string Poco::URI::_fragment
private

Definition at line 366 of file URI.h.

◆ _host

std::string Poco::URI::_host
private

Definition at line 362 of file URI.h.

◆ _path

std::string Poco::URI::_path
private

Definition at line 364 of file URI.h.

◆ _port

unsigned short Poco::URI::_port
private

Definition at line 363 of file URI.h.

◆ _query

std::string Poco::URI::_query
private

Definition at line 365 of file URI.h.

◆ _scheme

std::string Poco::URI::_scheme
private

Definition at line 360 of file URI.h.

◆ _userInfo

std::string Poco::URI::_userInfo
private

Definition at line 361 of file URI.h.

◆ ILLEGAL

const std::string Poco::URI::ILLEGAL
staticprotected

Definition at line 357 of file URI.h.

◆ RESERVED_FRAGMENT

const std::string Poco::URI::RESERVED_FRAGMENT
staticprotected

Definition at line 356 of file URI.h.

◆ RESERVED_PATH

const std::string Poco::URI::RESERVED_PATH
staticprotected

Builds the path from the given segments.

Definition at line 353 of file URI.h.

◆ RESERVED_QUERY

const std::string Poco::URI::RESERVED_QUERY
staticprotected

Definition at line 354 of file URI.h.

◆ RESERVED_QUERY_PARAM

const std::string Poco::URI::RESERVED_QUERY_PARAM
staticprotected

Definition at line 355 of file URI.h.


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