28 #ifndef WEBSOCKETPP_URI_HPP 29 #define WEBSOCKETPP_URI_HPP 50 explicit uri(std::string
const & uri_string) : m_valid(false) {
51 std::string::const_iterator it;
52 std::string::const_iterator temp;
56 it = uri_string.begin();
57 size_t uri_len = uri_string.length();
59 if (uri_len >= 7 && std::equal(it,it+6,
"wss://")) {
63 }
else if (uri_len >= 6 && std::equal(it,it+5,
"ws://")) {
67 }
else if (uri_len >= 8 && std::equal(it,it+7,
"http://")) {
71 }
else if (uri_len >= 9 && std::equal(it,it+8,
"https://")) {
92 while (temp != uri_string.end()) {
99 if (temp == uri_string.end()) {
104 m_host.append(it,temp);
107 if (it == uri_string.end()) {
109 }
else if (*it ==
'/') {
112 }
else if (*it ==
':') {
123 if (it == uri_string.end()) {
126 }
else if (*it ==
'/') {
128 }
else if (*it ==
':') {
141 if (it == uri_string.end()) {
147 }
else if (*it ==
'/') {
156 m_port = get_port_from_string(port, ec);
163 m_resource.append(it,uri_string.end());
169 uri(
bool secure, std::string
const & host, uint16_t port,
171 : m_scheme(secure ?
"wss" :
"ws")
173 , m_resource(resource.empty() ?
"/" : resource)
178 uri(
bool secure, std::string
const & host, std::string
const &
resource)
179 : m_scheme(secure ?
"wss" :
"ws")
181 , m_resource(resource.empty() ?
"/" : resource)
182 , m_port(secure ? uri_default_secure_port : uri_default_port)
186 uri(
bool secure, std::string
const & host, std::string
const & port,
188 : m_scheme(secure ?
"wss" :
"ws")
190 , m_resource(resource.empty() ?
"/" : resource)
194 m_port = get_port_from_string(port,ec);
198 uri(std::string
const & scheme, std::string
const & host, uint16_t port,
202 , m_resource(resource.empty() ?
"/" : resource)
204 , m_secure(scheme ==
"wss" || scheme ==
"https")
207 uri(std::string scheme, std::string
const & host, std::string
const &
resource)
210 , m_resource(resource.empty() ?
"/" : resource)
211 , m_port((scheme ==
"wss" || scheme ==
"https") ? uri_default_secure_port : uri_default_port)
212 , m_secure(scheme ==
"wss" || scheme ==
"https")
215 uri(std::string
const & scheme, std::string
const & host,
216 std::string
const & port, std::string
const &
resource)
219 , m_resource(resource.empty() ?
"/" : resource)
220 , m_secure(scheme ==
"wss" || scheme ==
"https")
223 m_port = get_port_from_string(port,ec);
244 if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
248 p << m_host <<
":" << m_port;
255 p << m_host <<
":" << m_port;
276 s << m_scheme <<
"://" << m_host;
278 if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
294 std::size_t
found = m_resource.find(
'?');
295 if (found != std::string::npos) {
296 return m_resource.substr(found + 1);
320 uint16_t get_port_from_string(std::string
const & port, lib::error_code &
323 ec = lib::error_code();
326 return (m_secure ? uri_default_secure_port : uri_default_port);
329 unsigned int t_port =
static_cast<unsigned int>(atoi(port.c_str()));
331 if (t_port > 65535) {
339 return static_cast<uint16_t
>(t_port);
342 std::string m_scheme;
344 std::string m_resource;
355 #endif // WEBSOCKETPP_URI_HPP lib::error_code make_error_code(error::value e)
std::string const & get_resource() const
std::string get_host_port() const
std::string const & get_host() const
uint16_t get_port() 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)
std::string get_query() const
Return the query portion.
uri(std::string scheme, std::string const &host, std::string const &resource)
std::string get_port_str() const
uri(bool secure, std::string const &host, std::string const &resource)
Namespace for the WebSocket++ project.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
uri(std::string const &uri_string)
std::string get_authority() const
static uint16_t const uri_default_port
Default port for ws://.
std::string const & get_scheme() const
uri(std::string const &scheme, std::string const &host, uint16_t port, std::string const &resource)
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)