Axmol Engine 2.4.0-258ceca
Loading...
Searching...
No Matches
Uri Class Reference

Class representing a URI. More...

#include <Uri.h>

Public Member Functions

 Uri ()
 Default constructor.
 
 Uri (const Uri &o)
 Copy constructor.
 
 Uri (Uri &&o)
 Move constructor.
 
Urioperator= (const Uri &o)
 Copy assignment.
 
Urioperator= (Uri &&o)
 Move assignment.
 
bool operator== (const Uri &o) const
 Checks whether two Uri instances contain the same values.
 
bool isValid () const
 Checks wether it's a valid URI.
 
bool isSecure () const
 Checks whether it's a SSL connection.
 
std::string_view getScheme () const
 Gets the scheme name for this URI.
 
std::string_view getUserName () const
 Gets the user name with the specified URI.
 
std::string_view getPassword () const
 Gets the password with the specified URI.
 
std::string_view getHost () const
 Get host part of URI.
 
std::string_view getHostName () const
 Get host part of URI.
 
uint16_t getPort () const
 Gets the port number of the URI.
 
std::string_view getPath () const
 Gets the path part of the URI.
 
std::string_view getPathEtc () const
 Gets the path, query and fragment parts of the URI.
 
std::string_view getQuery () const
 Gets the query part of the URI.
 
std::string_view getFragment () const
 Gets the fragment part of the URI.
 
std::string_view getAuthority () const
 Gets the authority part (userName, password, host and port) of the URI.
 
std::string toString () const
 Gets a string representation of the URI.
 
const std::vector< std::pair< std::string, std::string > > & getQueryParams ()
 Get query parameters as key-value pairs.
 
void clear ()
 Clears all parts of the URI.
 

Static Public Member Functions

static Uri parse (std::string_view str)
 Parse a Uri from a string.
 

Detailed Description

Class representing a URI.

Consider http://www.facebook.com/foo/bar?key=foo#anchor

The URI is broken down into its parts: scheme ("http"), authority (ie. host and port, in most cases: "www.facebook.com"), path ("/foo/bar"), query ("key=foo") and fragment ("anchor"). The scheme is lower-cased.

If this Uri represents a URL, note that, to prevent ambiguity, the component parts are NOT percent-decoded; you should do this yourself with uriUnescape() (for the authority and path) and uriUnescape(..., UriEscapeMode::QUERY) (for the query, but probably only after splitting at '&' to identify the individual parameters).

Member Function Documentation

◆ parse()

static Uri parse ( std::string_view str)
static

Parse a Uri from a string.

Throws std::invalid_argument on parse error.

◆ getHost()

std::string_view getHost ( ) const
inline

Get host part of URI.

If host is an IPv6 address, square brackets will be returned, for example: "[::1]".

◆ getHostName()

std::string_view getHostName ( ) const
inline

Get host part of URI.

If host is an IPv6 address, square brackets will not be returned, for exmaple "::1"; otherwise it returns the same thing as getHost().

getHostName() is what one needs to call if passing the host to any other tool or API that connects to that host/port; e.g. getaddrinfo() only understands IPv6 host without square brackets

◆ getAuthority()

std::string_view getAuthority ( ) const
inline

Gets the authority part (userName, password, host and port) of the URI.

Note
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.

◆ getQueryParams()

const std::vector< std::pair< std::string, std::string > > & getQueryParams ( )

Get query parameters as key-value pairs.

e.g. for URI containing query string: key1=foo&key2=&key3&=bar&=bar= In returned list, there are 3 entries: "key1" => "foo" "key2" => "" "key3" => "" Parts "=bar" and "=bar=" are ignored, as they are not valid query parameters. "=bar" is missing parameter name, while "=bar=" has more than one equal signs, we don't know which one is the delimiter for key and value.

Note, this method is not thread safe, it might update internal state, but only the first call to this method update the state. After the first call is finished, subsequent calls to this method are thread safe.

Returns
query parameter key-value pairs in a vector, each element is a pair of which the first element is parameter name and the second one is parameter value

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