34 #include "cpprest/asyncrt_utils.h"
35 #include "cpprest/details/basic_types.h"
46 m_scheme(other.m_scheme),
48 m_user_info(other.m_user_info),
50 m_query(other.m_query),
51 m_fragment(other.m_fragment),
59 m_scheme = other.m_scheme;
60 m_host = other.m_host;
61 m_user_info = other.m_user_info;
62 m_path = other.m_path;
63 m_query = other.m_query;
64 m_fragment = other.m_fragment;
65 m_port = other.m_port;
71 m_scheme(std::move(other.m_scheme)),
72 m_host(std::move(other.m_host)),
73 m_user_info(std::move(other.m_user_info)),
74 m_path(std::move(other.m_path)),
75 m_query(std::move(other.m_query)),
76 m_fragment(std::move(other.m_fragment)),
84 m_scheme = std::move(other.m_scheme);
85 m_host = std::move(other.m_host);
86 m_user_info = std::move(other.m_user_info);
87 m_path = std::move(other.m_path);
88 m_query = std::move(other.m_query);
89 m_fragment = std::move(other.m_fragment);
90 m_port = other.m_port;
95 _ASYNCRTIMP utility::string_t join();
97 utility::string_t m_scheme;
98 utility::string_t m_host;
99 utility::string_t m_user_info;
100 utility::string_t m_path;
101 utility::string_t m_query;
102 utility::string_t m_fragment;
118 const char* what()
const CPPREST_NOEXCEPT
120 return m_msg.c_str();
183 _ASYNCRTIMP
static utility::string_t __cdecl
encode_uri(
const utility::string_t &raw, uri::components::component = components::full_uri);
191 _ASYNCRTIMP
static utility::string_t __cdecl
encode_data_string(
const utility::string_t &utf8data);
198 _ASYNCRTIMP
static utility::string_t __cdecl
decode(
const utility::string_t &encoded);
205 _ASYNCRTIMP
static std::vector<utility::string_t> __cdecl
split_path(
const utility::string_t &
path);
212 _ASYNCRTIMP
static std::map<utility::string_t, utility::string_t> __cdecl
split_query(
const utility::string_t &
query);
219 _ASYNCRTIMP
static bool __cdecl
validate(
const utility::string_t &uri_string);
224 uri() { m_uri = _XPLATSTR(
"/");};
231 _ASYNCRTIMP
uri(
const utility::char_t *uri_string);
238 _ASYNCRTIMP
uri(
const utility::string_t &uri_string);
245 m_components(other.m_components)
256 m_components = other.m_components;
265 m_uri(std::move(other.m_uri)),
266 m_components(std::move(other.m_components))
276 m_uri = std::move(other.m_uri);
277 m_components = std::move(other.m_components);
286 const utility::string_t &
scheme()
const {
return m_components.m_scheme; }
292 const utility::string_t &
user_info()
const {
return m_components.m_user_info; }
298 const utility::string_t &
host()
const {
return m_components.m_host; }
304 int port()
const {
return m_components.m_port; }
310 const utility::string_t &
path()
const {
return m_components.m_path; }
316 const utility::string_t &
query()
const {
return m_components.m_query; }
322 const utility::string_t &
fragment()
const {
return m_components.m_fragment; }
341 return this->m_uri.empty() || this->m_uri == _XPLATSTR(
"/");
353 return !
is_empty() && ((
host() == _XPLATSTR(
"localhost")) || (
host().size() > 4 &&
host().substr(0,4) == _XPLATSTR(
"127.")));
364 return !
is_empty() && (this->
host() == _XPLATSTR(
"*") || this->
host() == _XPLATSTR(
"+"));
416 return path().empty() ||
path() == _XPLATSTR(
"/");
428 _ASYNCRTIMP
bool operator == (
const uri &other)
const;
430 bool operator < (
const uri &other)
const
432 return m_uri < other.m_uri;
435 bool operator != (
const uri &other)
const
437 return !(this->operator == (other));
441 friend class uri_builder;
444 _ASYNCRTIMP
static utility::string_t __cdecl encode_impl(
const utility::string_t &raw,
const std::function<
bool __cdecl(
int)>& should_encode);
446 utility::string_t m_uri;
447 details::uri_components m_components;
uri & operator=(const uri &other)
Copy assignment operator.
Definition: base_uri.h:251
const utility::string_t & path() const
Get the path component of the URI as an encoded string.
Definition: base_uri.h:310
_ASYNCRTIMP uri authority() const
Creates a new uri object with the same authority portion as this one, omitting the resource and query...
uri(const uri &other)
Copy constructor.
Definition: base_uri.h:243
bool is_path_empty() const
Returns whether the path portion of this URI is empty
Definition: base_uri.h:414
_ASYNCRTIMP uri resource() const
Gets the path, query, and fragment portion of this uri, which may be empty.
const utility::string_t & query() const
Get the query component of the URI as an encoded string.
Definition: base_uri.h:316
A flexible, protocol independent URI implementation.
Definition: base_uri.h:151
The various components of a URI. This enum is used to indicate which URI component is being encoded t...
Definition: base_uri.h:162
static _ASYNCRTIMP utility::string_t __cdecl decode(const utility::string_t &encoded)
Decodes an encoded string.
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
bool is_host_wildcard() const
A wildcard URI is one which refers to all hostnames that resolve to the local machine (using the * or...
Definition: base_uri.h:362
bool is_host_portable() const
A portable URI is one with a hostname that can be resolved globally (used from another machine)...
Definition: base_uri.h:376
bool is_port_default() const
Definition: base_uri.h:386
int port() const
Get the port component of the URI. Returns -1 if no port is specified.
Definition: base_uri.h:304
uri(uri &&other) CPPREST_NOEXCEPT
Move constructor.
Definition: base_uri.h:264
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 individu...
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...
Definition: base_uri.h:351
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 hexa...
bool is_authority() const
An "authority" URI is one with only a scheme, optional userinfo, hostname, and (optional) port...
Definition: base_uri.h:395
static _ASYNCRTIMP bool __cdecl validate(const utility::string_t &uri_string)
Validates a string as a URI.
utility::string_t to_string() const
Returns the full (encoded) URI as a string.
Definition: base_uri.h:423
A single exception type to represent errors in parsing, encoding, and decoding URIs.
Definition: base_uri.h:110
const utility::string_t & host() const
Get the host component of the URI as an encoded string.
Definition: base_uri.h:298
uri & operator=(uri &&other) CPPREST_NOEXCEPT
Move assignment operator
Definition: base_uri.h:272
static _ASYNCRTIMP std::vector< utility::string_t > __cdecl split_path(const utility::string_t &path)
Splits a path into its hierarchical components.
bool is_empty() const
An empty URI specifies no components, and serves as a default value
Definition: base_uri.h:339
bool has_same_authority(const uri &other) const
Returns whether the other URI has the same authority as this one
Definition: base_uri.h:405
Definition: base_uri.h:40
const utility::string_t & user_info() const
Get the user information component of the URI as an encoded string.
Definition: base_uri.h:292
const utility::string_t & fragment() const
Get the fragment component of the URI as an encoded string.
Definition: base_uri.h:322
uri()
Creates an empty uri
Definition: base_uri.h:224
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.
const utility::string_t & scheme() const
Get the scheme component of the URI as an encoded string.
Definition: base_uri.h:286