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,
171 std::string
const & resource)
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)
187 uri(
bool secure, std::string
const & host, std::string
const & port,
188 std::string
const & resource)
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,
200 std::string
const & resource)
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)
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);
228 bool get_valid()
const {
232 bool get_secure()
const {
236 std::string
const & get_scheme()
const {
240 std::string
const & get_host()
const {
244 std::string get_host_port()
const {
249 p << m_host <<
":" << m_port;
254 std::string get_authority()
const {
256 p << m_host <<
":" << m_port;
260 uint16_t get_port()
const {
264 std::string get_port_str()
const {
270 std::string
const & get_resource()
const {
274 std::string str()
const {
277 s << m_scheme <<
"://" << m_host;
295 std::size_t found = m_resource.find(
'?');
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();
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;