![]() |
C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
|
A flexible, protocol independent URI implementation. More...
#include <base_uri.h>
Classes | |
class | components |
The various components of a URI. This enum is used to indicate which URI component is being encoded to the encode_uri_component. This allows specific encoding to be performed. More... | |
Public Member Functions | |
uri () | |
Creates an empty uri More... | |
_ASYNCRTIMP | uri (const utility::char_t *uri_string) |
Creates a URI from the given encoded string. This will throw an exception if the string does not contain a valid URI. Use uri::validate if processing user-input. More... | |
_ASYNCRTIMP | uri (const utility::string_t &uri_string) |
Creates a URI from the given encoded string. This will throw an exception if the string does not contain a valid URI. Use uri::validate if processing user-input. More... | |
uri (const uri &other) | |
Copy constructor. More... | |
uri & | operator= (const uri &other) |
Copy assignment operator. More... | |
uri (uri &&other) CPPREST_NOEXCEPT | |
Move constructor. More... | |
uri & | operator= (uri &&other) CPPREST_NOEXCEPT |
Move assignment operator More... | |
const utility::string_t & | scheme () const |
Get the scheme component of the URI as an encoded string. More... | |
const utility::string_t & | user_info () const |
Get the user information component of the URI as an encoded string. More... | |
const utility::string_t & | host () const |
Get the host component of the URI as an encoded string. More... | |
int | port () const |
Get the port component of the URI. Returns -1 if no port is specified. More... | |
const utility::string_t & | path () const |
Get the path component of the URI as an encoded string. More... | |
const utility::string_t & | query () const |
Get the query component of the URI as an encoded string. More... | |
const utility::string_t & | fragment () const |
Get the fragment component of the URI as an encoded string. More... | |
_ASYNCRTIMP uri | authority () const |
Creates a new uri object with the same authority portion as this one, omitting the resource and query portions. More... | |
_ASYNCRTIMP uri | resource () const |
Gets the path, query, and fragment portion of this uri, which may be empty. More... | |
bool | is_empty () const |
An empty URI specifies no components, and serves as a default value More... | |
bool | is_host_loopback () const |
A loopback URI is one which refers to a hostname or ip address with meaning only on the local machine. More... | |
bool | is_host_wildcard () const |
A wildcard URI is one which refers to all hostnames that resolve to the local machine (using the * or +) More... | |
bool | is_host_portable () const |
A portable URI is one with a hostname that can be resolved globally (used from another machine). More... | |
bool | is_port_default () const |
bool | is_authority () const |
An "authority" URI is one with only a scheme, optional userinfo, hostname, and (optional) port. More... | |
bool | has_same_authority (const uri &other) const |
Returns whether the other URI has the same authority as this one More... | |
bool | is_path_empty () const |
Returns whether the path portion of this URI is empty More... | |
utility::string_t | to_string () const |
Returns the full (encoded) URI as a string. More... | |
_ASYNCRTIMP bool | operator== (const uri &other) const |
bool | operator< (const uri &other) const |
bool | operator!= (const uri &other) const |
Static Public Member Functions | |
static _ASYNCRTIMP utility::string_t __cdecl | encode_uri (const utility::string_t &raw, uri::components::component=components::full_uri) |
Encodes a URI component according to RFC 3986. Note if a full URI is specified instead of an individual URI component all characters not in the unreserved set are escaped. More... | |
static _ASYNCRTIMP utility::string_t __cdecl | encode_data_string (const utility::string_t &utf8data) |
Encodes a string by converting all characters except for RFC 3986 unreserved characters to their hexadecimal representation. More... | |
static _ASYNCRTIMP utility::string_t __cdecl | decode (const utility::string_t &encoded) |
Decodes an encoded string. More... | |
static _ASYNCRTIMP std::vector< utility::string_t > __cdecl | split_path (const utility::string_t &path) |
Splits a path into its hierarchical components. More... | |
static _ASYNCRTIMP std::map< utility::string_t, utility::string_t > __cdecl | split_query (const utility::string_t &query) |
Splits a query into its key-value components. More... | |
static _ASYNCRTIMP bool __cdecl | validate (const utility::string_t &uri_string) |
Validates a string as a URI. More... | |
Friends | |
class | uri_builder |
A flexible, protocol independent URI implementation.
URI instances are immutable. Querying the various fields on an emtpy URI will return empty strings. Querying various diagnostic members on an empty URI will return false.
This implementation accepts both URIs ('http://msn.com/path') and URI relative-references ('/path?query::frag').
This implementation does not provide any scheme-specific handling – an example of this would be the following: 'http://path1/path'. This is a valid URI, but it's not a valid http-uri – that is, it's syntactically correct but does not conform to the requirements of the http scheme (http requires a host). We could provide this by allowing a pluggable 'scheme' policy-class, which would provide extra capability for validating and canonicalizing a URI according to scheme, and would introduce a layer of type-safety for URIs of differing schemes, and thus differing semantics.
One issue with implementing a scheme-independent URI facility is that of comparing for equality. For instance, these URIs are considered equal 'http://msn.com', 'http://msn.com:80'. That is – the 'default' port can be either omitted or explicit. Since we don't have a way to map a scheme to it's default port, we don't have a way to know these are equal. This is just one of a class of issues with regard to scheme-specific behavior.
|
inline |
Creates an empty uri
_ASYNCRTIMP web::uri::uri | ( | const utility::char_t * | uri_string | ) |
Creates a URI from the given encoded string. This will throw an exception if the string does not contain a valid URI. Use uri::validate if processing user-input.
uri_string | A pointer to an encoded string to create the URI instance. |
_ASYNCRTIMP web::uri::uri | ( | const utility::string_t & | uri_string | ) |
Creates a URI from the given encoded string. This will throw an exception if the string does not contain a valid URI. Use uri::validate if processing user-input.
uri_string | An encoded URI string to create the URI instance. |
|
inline |
Copy constructor.
|
inline |
Move constructor.
_ASYNCRTIMP uri web::uri::authority | ( | ) | const |
Creates a new uri object with the same authority portion as this one, omitting the resource and query portions.
|
static |
Decodes an encoded string.
encoded | The URI as a string. |
|
static |
Encodes a string by converting all characters except for RFC 3986 unreserved characters to their hexadecimal representation.
utf8data | The UTF-8 string data. |
|
static |
Encodes a URI component according to RFC 3986. Note if a full URI is specified instead of an individual URI component all characters not in the unreserved set are escaped.
raw | The URI as a string. |
|
inline |
Get the fragment component of the URI as an encoded string.
|
inline |
Returns whether the other URI has the same authority as this one
other | The URI to compare the authority with. |
true
if both the URI's have the same authority, false
otherwise.
|
inline |
Get the host component of the URI as an encoded string.
|
inline |
An "authority" URI is one with only a scheme, optional userinfo, hostname, and (optional) port.
true
if this is an "authority" URI, false
otherwise.
|
inline |
An empty URI specifies no components, and serves as a default value
|
inline |
A loopback URI is one which refers to a hostname or ip address with meaning only on the local machine.
Examples include "locahost", or ip addresses in the loopback range (127.0.0.0/24).
true
if this URI references the local host, false
otherwise.
|
inline |
A portable URI is one with a hostname that can be resolved globally (used from another machine).
true
if this URI can be resolved globally (used from another machine), false
otherwise.The hostname "localhost" is a reserved name that is guaranteed to resolve to the local machine, and cannot be used for inter-machine communication. Likewise the hostnames "*" and "+" on Windows represent wildcards, and do not map to a resolvable address.
|
inline |
A wildcard URI is one which refers to all hostnames that resolve to the local machine (using the * or +)
http://*:80
|
inline |
Returns whether the path portion of this URI is empty
true
if the path portion of this URI is empty, false
otherwise.
|
inline |
A default port is one where the port is unspecified, and will be determined by the operating system. The choice of default port may be dictated by the scheme (http -> 80) or not.
true
if this URI instance has a default port, false
otherwise.
|
inline |
Get the path component of the URI as an encoded string.
|
inline |
Get the port component of the URI. Returns -1 if no port is specified.
|
inline |
Get the query component of the URI as an encoded string.
_ASYNCRTIMP uri web::uri::resource | ( | ) | const |
Gets the path, query, and fragment portion of this uri, which may be empty.
|
inline |
Get the scheme component of the URI as an encoded string.
|
static |
Splits a path into its hierarchical components.
path | The path as a string |
std::vector<utility::string_t>
containing the segments in the path.
|
static |
Splits a query into its key-value components.
query | The query string |
std::map<utility::string_t, utility::string_t>
containing the key-value components of the query.
|
inline |
Returns the full (encoded) URI as a string.
|
inline |
Get the user information component of the URI as an encoded string.
|
static |
Validates a string as a URI.
uri_string | The URI string to be validated. |
true
if the given string represents a valid URI, false
otherwise.