Gorgon Game Engine
URI Class Reference

Represents an unfolded URI. More...

Public Member Functions

 URI ()=default
 Empty constructor. Does not set scheme thus would not be a valid URI. More...
 
 URI (const char *str)
 Builds a new URI from the given string. More...
 
 URI (const std::string &scheme, const std::string &host, const std::string &path, const std::string &query="", const std::string &fragment="")
 Creates a new URI by filling in fields. More...
 
 URI (const std::string &scheme, const std::string &host, int port, const std::string &path, const std::string &query="", const std::string &fragment="")
 Creates a new URI by filling in fields. More...
 
 URI (const std::string &str, bool inpagelink=false)
 Builds a new URI from the given string. More...
 
void Combine (const std::string &link)
 Combines a relative URI into this URI. More...
 
std::string Convert () const
 Converts this URI to a properly encoded string. More...
 
bool IsValid () const
 Returns if this URI is valid. More...
 
 operator bool () const
 Returns if this URI is valid. More...
 
 operator std::string () const
 Converts this URI to a properly encoded string. More...
 
bool operator!= (const URI &other) const
 Compares two URIs in their simplest forms. More...
 
URI operator+ (const std::string &link)
 
bool operator== (const URI &other) const
 Compares two URIs in their simplest forms. More...
 

Public Attributes

std::string fragment
 Fragment of the resource (anchor in HTML) More...
 
std::string host
 Host address, either IP/domain name or empty, ex: darkgaze.org. More...
 
std::string path
 Path of the resource. Segments must be separated by /. You may use URIPath to construct a path. More...
 
int port
 The port number, 0 means it is not defined. More...
 
std::string query
 Query for the resource, must be properly escaped and encoded, you may use HTTPQuery to build http query string. More...
 
std::string scheme
 Scheme of the URI, ex: http. More...
 
std::string userinfo
 User information. More...
 

Detailed Description

Represents an unfolded URI.

Can be used to parse a URI string or build one according to RFC 3986.

#include <Gorgon/Network/HTTP.h>
...
std::cout<<Gorgon::Network::HTTP::BlockingGetText(URI("http", "darkgaze.org", "path/to/data.php"))<<std::endl;

Constructor & Destructor Documentation

◆ URI() [1/5]

URI ( )
default

Empty constructor. Does not set scheme thus would not be a valid URI.

◆ URI() [2/5]

URI ( const std::string &  scheme,
const std::string &  host,
const std::string &  path,
const std::string &  query = "",
const std::string &  fragment = "" 
)

Creates a new URI by filling in fields.

◆ URI() [3/5]

URI ( const std::string &  scheme,
const std::string &  host,
int  port,
const std::string &  path,
const std::string &  query = "",
const std::string &  fragment = "" 
)

Creates a new URI by filling in fields.

◆ URI() [4/5]

URI ( const std::string &  str,
bool  inpagelink = false 
)

Builds a new URI from the given string.

May throw URIError. This constructor will not check if the URI is really valid. Use IsValid function for this purpose. If this URI is embedded inside another URI and possibly a relative link, set inpagelink to true. Otherwise, URIs without scheme will be treated having a host. For instance when inpagelink is false, in URI darkgaze.org/my/path darkgaze.org would be treated as host name.

References URI::fragment, URI::host, URI::path, URI::port, URI::query, URI::scheme, and URI::userinfo.

◆ URI() [5/5]

URI ( const char *  str)

Builds a new URI from the given string.

May throw URIError. This constructor will not check if the URI is really valid. Use IsValid function for this purpose.

Member Function Documentation

◆ Combine()

void Combine ( const std::string &  link)

Combines a relative URI into this URI.

Can be used to normalize links in a document. Care should be taken while using URIPath with this function as URIPath cannot represent relative paths.

References URI::URI(), URI::fragment, URI::host, URI::path, URI::query, and URI::scheme.

◆ Convert()

std::string Convert ( ) const

Converts this URI to a properly encoded string.

◆ IsValid()

bool IsValid ( ) const

Returns if this URI is valid.

This function checks if scheme is valid in format. Additionally, if the scheme is http, https and ftp, checks if the host is set.

References URI::host, Gorgon::Encoding::PCTEncode(), and URI::scheme.

◆ operator bool()

operator bool ( ) const

Returns if this URI is valid.

References URI::IsValid().

◆ operator std::string()

operator std::string ( ) const

Converts this URI to a properly encoded string.

References Gorgon::Encoding::PCTEncode(), and Gorgon::String::ToLower().

◆ operator!=()

bool operator!= ( const URI other) const

Compares two URIs in their simplest forms.

Note that URIs with different fragments point to different places in the same resource and will not be used in comparison. This is also recommended by RFC 3986

◆ operator+()

URI operator+ ( const std::string &  link)

References URI::Combine().

◆ operator==()

bool operator== ( const URI other) const

Compares two URIs in their simplest forms.

Note that URIs with different fragments point to different places in the same resource and will not be used in comparison. This is also recommended by RFC 3986

References URI::host, URI::path, URI::port, URI::query, URI::scheme, Gorgon::String::ToLower(), and URI::userinfo.

Member Data Documentation

◆ fragment

std::string fragment

Fragment of the resource (anchor in HTML)

◆ host

std::string host

Host address, either IP/domain name or empty, ex: darkgaze.org.

◆ path

std::string path

Path of the resource. Segments must be separated by /. You may use URIPath to construct a path.

◆ port

int port

The port number, 0 means it is not defined.

◆ query

std::string query

Query for the resource, must be properly escaped and encoded, you may use HTTPQuery to build http query string.

◆ scheme

std::string scheme

Scheme of the URI, ex: http.

Scheme cannot be encoded, thus should only start with an alpha character and should only contain Alphanumeric characters as well as +, - and .

◆ userinfo

std::string userinfo

User information.

Use : to separate password. Use of password is no longer recommended by RFC unless it is empty.


The documentation for this class was generated from the following files:
Gorgon::Encoding::URI::URI
URI()=default
Empty constructor. Does not set scheme thus would not be a valid URI.