28 #ifndef WEBSOCKETPP_URI_HPP 29 #define WEBSOCKETPP_URI_HPP 51 explicit uri(std::string
const & uri_string) : m_valid(false) {
52 std::string::const_iterator it;
53 std::string::const_iterator temp;
57 it = uri_string.begin();
58 size_t uri_len = uri_string.length();
60 if (uri_len >= 7 && std::equal(it,it+6,
"wss://")) {
64 }
else if (uri_len >= 6 && std::equal(it,it+5,
"ws://")) {
68 }
else if (uri_len >= 8 && std::equal(it,it+7,
"http://")) {
72 }
else if (uri_len >= 9 && std::equal(it,it+8,
"https://")) {
93 while (temp != uri_string.end()) {
100 if (temp == uri_string.end()) {
105 m_host.append(it,temp);
108 if (it == uri_string.end()) {
110 }
else if (*it ==
'/') {
113 }
else if (*it ==
':') {
124 if (it == uri_string.end()) {
127 }
else if (*it ==
'/') {
129 }
else if (*it ==
':') {
142 if (it == uri_string.end()) {
148 }
else if (*it ==
'/') {
157 m_port = get_port_from_string(port, ec);
164 m_resource.append(it,uri_string.end());
170 uri(
bool secure, std::string
const & host, uint16_t port,
172 : m_scheme(secure ?
"wss" :
"ws")
174 , m_resource(resource.empty() ?
"/" : resource)
179 uri(
bool secure, std::string
const & host, std::string
const &
resource)
180 : m_scheme(secure ?
"wss" :
"ws")
182 , m_resource(resource.empty() ?
"/" : resource)
183 , m_port(secure ? uri_default_secure_port : uri_default_port)
187 uri(
bool secure, std::string
const & host, std::string
const & port,
189 : m_scheme(secure ?
"wss" :
"ws")
191 , m_resource(resource.empty() ?
"/" : resource)
195 m_port = get_port_from_string(port,ec);
199 uri(std::string
const & scheme, std::string
const & host, uint16_t port,
203 , m_resource(resource.empty() ?
"/" : resource)
205 , m_secure(scheme ==
"wss" || scheme ==
"https")
208 uri(std::string scheme, std::string
const & host, std::string
const &
resource)
211 , m_resource(resource.empty() ?
"/" : resource)
212 , m_port((scheme ==
"wss" || scheme ==
"https") ? uri_default_secure_port : uri_default_port)
213 , m_secure(scheme ==
"wss" || scheme ==
"https")
216 uri(std::string
const & scheme, std::string
const & host,
217 std::string
const & port, std::string
const &
resource)
220 , m_resource(resource.empty() ?
"/" : resource)
221 , m_secure(scheme ==
"wss" || scheme ==
"https")
224 m_port = get_port_from_string(port,ec);
245 if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
249 p << m_host <<
":" << m_port;
256 p << m_host <<
":" << m_port;
277 s << m_scheme <<
"://" << m_host;
279 if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
296 if (found != std::string::npos) {
297 return m_resource.substr(found + 1);
321 uint16_t get_port_from_string(std::string
const & port, lib::error_code &
324 ec = lib::error_code();
327 return (m_secure ? uri_default_secure_port : uri_default_port);
330 unsigned int t_port =
static_cast<unsigned int>(atoi(port.c_str()));
332 if (t_port > 65535) {
340 return static_cast<uint16_t
>(t_port);
343 std::string m_scheme;
345 std::string m_resource;
356 #endif // WEBSOCKETPP_URI_HPP std::string get_host_port() const
lib::error_code make_error_code(error::value e)
span_CONFIG_SIZE_TYPE size_t
std::string get_authority() const
uri(std::string const &scheme, std::string const &host, std::string const &port, std::string const &resource)
uri(bool secure, std::string const &host, std::string const &port, std::string const &resource)
uri(std::string scheme, std::string const &host, std::string const &resource)
uri(bool secure, std::string const &host, std::string const &resource)
std::string get_query() const
Return the query portion.
Namespace for the WebSocket++ project.
std::string get_port_str() const
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
uri(std::string const &uri_string)
std::string const & get_scheme() const
std::string const & get_resource() const
uint16_t get_port() const
static uint16_t const uri_default_port
Default port for ws://.
uri(std::string const &scheme, std::string const &host, uint16_t port, std::string const &resource)
std::string const & get_host() const
static uint16_t const uri_default_secure_port
Default port for wss://.
uri(bool secure, std::string const &host, uint16_t port, std::string const &resource)